fix: semicolon on redirect block, port 443 for ssl

This commit is contained in:
Mahdi Dibaiee 2017-04-25 09:40:25 +04:30
parent cee3ff4e72
commit 1a2c6f5fe4

View File

@ -16,7 +16,7 @@ module Types ( ServerType (..)
toServerParams (("email", Just value):xs) = (toServerParams xs) { email = value } toServerParams (("email", Just value):xs) = (toServerParams xs) { email = value }
toServerParams (("ssl", Nothing):xs) = (toServerParams xs) { ssl = True } toServerParams (("ssl", Nothing):xs) = (toServerParams xs) { ssl = True }
toServerParams (("directory-listing", Nothing):xs) = (toServerParams xs) { directoryListing = True } toServerParams (("directory-listing", Nothing):xs) = (toServerParams xs) { directoryListing = True }
toServerParams (_:xs) = (toServerParams xs) toServerParams (_:xs) = toServerParams xs
toServerParams _ = def toServerParams _ = def
data ServerType = Static | PortForwarding deriving (Show, Eq) data ServerType = Static | PortForwarding deriving (Show, Eq)
@ -41,14 +41,14 @@ module Types ( ServerType (..)
, serverType = Static } , serverType = Static }
instance Show ServerParams where instance Show ServerParams where
show (ServerParams { directory, domain, port, forward, email, ssl, serverType, directoryListing }) = show ServerParams { directory, domain, port, forward, email, ssl, serverType, directoryListing } =
let redirect let redirect
| ssl = block "server" $ | ssl = block "server" $
keyvalue ([ ("listen", "80") keyvalue [ ("listen", "80")
, ("listen", "[::]:80") , ("listen", "[::]:80")
, ("server_name", domain) , ("server_name", domain)
, ("rewrite", "^ https://$server_name$request_uri? permanent") , ("rewrite", "^ https://$server_name$request_uri? permanent")
]) " " ] " "
| otherwise = "" | otherwise = ""
https https
| ssl = [ ("ssl_certificate", "/etc/letsencrypt/live/" ++ domain ++ "/fullchain.pem") | ssl = [ ("ssl_certificate", "/etc/letsencrypt/live/" ++ domain ++ "/fullchain.pem")
@ -56,7 +56,7 @@ module Types ( ServerType (..)
, ("include", "ssl.conf")] , ("include", "ssl.conf")]
| otherwise = [] | otherwise = []
listen = port ++ (if ssl then " ssl" else "") listen = if ssl then "443 ssl" else port
base = [ ("server_name", domain) base = [ ("server_name", domain)
, ("listen", listen) , ("listen", listen)
@ -67,14 +67,14 @@ module Types ( ServerType (..)
in in
case serverType of case serverType of
Static -> Static ->
(block "server" $ semicolon $ keyvalue (base ++ [("root", directory)]) " ") ++ "\n" ++ redirect block "server" $ semicolon $ keyvalue (base ++ [("root", directory)]) " " ++ "\n" ++ redirect
PortForwarding -> PortForwarding ->
let proxyBlock = block "location /" $ let proxyBlock = block "location /" $
semicolon $ semicolon $
keyvalue ([ ("proxy_pass", "http://127.0.0.1:" ++ forward) keyvalue [ ("proxy_pass", "http://127.0.0.1:" ++ forward)
, ("proxy_set_header", "X-Forwarded-Host $host") , ("proxy_set_header", "X-Forwarded-Host $host")
, ("proxy_set_header", "X-Forwarded-Server $host") , ("proxy_set_header", "X-Forwarded-Server $host")
, ("proxy_set_header", "X-Forwarded-For $proxy_add_x_forwarded_for") , ("proxy_set_header", "X-Forwarded-For $proxy_add_x_forwarded_for")
]) " " ] " "
in (block "server" $ semicolon (keyvalue base " ") ++ proxyBlock) ++ "\n" ++ redirect in block "server" $ semicolon (keyvalue base " ") ++ proxyBlock ++ "\n" ++ semicolon redirect