fix: write include
statement in nginx config
This commit is contained in:
@ -20,13 +20,16 @@ module System.Serverman.Actions.Nginx (nginx) where
|
||||
do
|
||||
-- Turn SSL off at first, because we have not yet received a certificate
|
||||
let content = show (params { ssl = False, port = "80" })
|
||||
parent = configDirectory serverService </> "configs"
|
||||
mainConfig = configDirectory serverService </> "nginx.conf"
|
||||
parent = configDirectory serverService </> "serverman-configs"
|
||||
path = parent </> domain
|
||||
targetDir = directory
|
||||
|
||||
createDirectoryIfMissing True targetDir
|
||||
createDirectoryIfMissing True parent
|
||||
|
||||
writeIncludeStatementIfMissing mainConfig parent
|
||||
|
||||
when ssl $ do
|
||||
let sslPath = configDirectory serverService </> "ssl.conf"
|
||||
writeFileIfMissing sslPath nginxSSL
|
||||
@ -71,4 +74,14 @@ module System.Serverman.Actions.Nginx (nginx) where
|
||||
writeFile path (show params)
|
||||
wait =<< restart
|
||||
|
||||
writeIncludeStatementIfMissing path target = do
|
||||
content <- readFile path
|
||||
|
||||
let statement = "include " ++ target ++ "/*"
|
||||
|
||||
when (not (statement `isInfixOf` content)) $ do
|
||||
let newContent = appendAfter content "http {" (" " ++ statement)
|
||||
|
||||
writeFile path newContent
|
||||
|
||||
|
||||
|
@ -29,15 +29,15 @@ module System.Serverman.Actions.WebServer (ServerParams(..), ServerType(..)) whe
|
||||
in
|
||||
case serverType conf of
|
||||
Static ->
|
||||
nginxBlock "server" $ keyvalue (base ++ [("root", directory conf)])
|
||||
block "server" $ keyvalue (base ++ [("root", directory conf)])
|
||||
|
||||
PortForwarding ->
|
||||
let proxyBlock = nginxBlock "location /" $
|
||||
let proxyBlock = block "location /" $
|
||||
keyvalue ([ ("proxy_pass", "http://127.0.0.1:" ++ forward conf)
|
||||
, ("proxy_set_header", "X-Forwarded-Host $host")
|
||||
, ("proxy_set_header", "X-Forwarded-Server $host")
|
||||
, ("proxy_set_header", "X-Forwarded-For $proxy_add_x_forwarded_for")
|
||||
])
|
||||
in nginxBlock "server" $ keyvalue base ++ proxyBlock
|
||||
in block "server" $ keyvalue base ++ proxyBlock
|
||||
|
||||
| otherwise = "Unknown service provider"
|
||||
|
Reference in New Issue
Block a user