Merge pull request #20366 from MarcWeber/submit/apache-port-to-listen

apache-httpd

Changed files
+52 -16
nixos
modules
services
web-servers
+29 -14
nixos/modules/services/web-servers/apache-httpd/default.nix
···
phpMajorVersion = head (splitString "." php.version);
-
getPort = cfg: if cfg.port != 0 then cfg.port else if cfg.enableSSL then 443 else 80;
extraModules = attrByPath ["extraModules"] [] mainCfg;
extraForeignModules = filter isAttrs extraModules;
···
makeServerInfo = cfg: {
# Canonical name must not include a trailing slash.
-
canonicalName =
-
(if cfg.enableSSL then "https" else "http") + "://" +
-
cfg.hostName +
-
(if getPort cfg != (if cfg.enableSSL then 443 else 80) then ":${toString (getPort cfg)}" else "");
# Admin address: inherit from the main server if not specified for
# a virtual host.
···
++ (map (svc: svc.robotsEntries) subservices)));
in ''
-
ServerName ${serverInfo.canonicalName}
${concatMapStrings (alias: "ServerAlias ${alias}\n") cfg.serverAliases}
···
</IfModule>
${let
-
ports = map getPort allHosts;
-
uniquePorts = uniqList {inputList = ports;};
-
in concatMapStrings (port: "Listen ${toString port}\n") uniquePorts
}
User ${mainCfg.user}
···
# Always enable virtual hosts; it doesn't seem to hurt.
${let
-
ports = map getPort allHosts;
-
uniquePorts = uniqList {inputList = ports;};
-
directives = concatMapStrings (port: "NameVirtualHost *:${toString port}\n") uniquePorts;
in optionalString (!version24) directives
}
${let
makeVirtualHost = vhost: ''
-
<VirtualHost *:${toString (getPort vhost)}>
${perServerConf false vhost}
</VirtualHost>
'';
···
message = "SSL is enabled for httpd, but sslServerCert and/or sslServerKey haven't been specified."; }
];
users.extraUsers = optionalAttrs (mainCfg.user == "wwwrun") (singleton
{ name = "wwwrun";
group = mainCfg.group;
···
};
};
-
}
···
phpMajorVersion = head (splitString "." php.version);
+
defaultListen = cfg: if cfg.enableSSL
+
then [{ip = "*"; port = 443;}]
+
else [{ip = "*"; port = 80;}];
+
+
getListen = cfg:
+
let list = (lib.optional (cfg.port != 0) {ip = "*"; port = cfg.port;}) ++ cfg.listen;
+
in if list == []
+
then defaultListen cfg
+
else list;
+
+
listenToString = l: "${l.ip}:${toString l.port}";
extraModules = attrByPath ["extraModules"] [] mainCfg;
extraForeignModules = filter isAttrs extraModules;
···
makeServerInfo = cfg: {
# Canonical name must not include a trailing slash.
+
canonicalNames =
+
let defaultPort = (head (defaultListen cfg)).port; in
+
map (port:
+
(if cfg.enableSSL then "https" else "http") + "://" +
+
cfg.hostName +
+
(if port != defaultPort then ":${toString port}" else "")
+
) (map (x: x.port) (getListen cfg));
# Admin address: inherit from the main server if not specified for
# a virtual host.
···
++ (map (svc: svc.robotsEntries) subservices)));
in ''
+
${concatStringsSep "\n" (map (n: "ServerName ${n}") serverInfo.canonicalNames)}
${concatMapStrings (alias: "ServerAlias ${alias}\n") cfg.serverAliases}
···
</IfModule>
${let
+
listen = concatMap getListen allHosts;
+
toStr = listen: "Listen ${listenToString listen}\n";
+
uniqueListen = uniqList {inputList = map toStr listen;};
+
in concatStrings uniqueListen
}
User ${mainCfg.user}
···
# Always enable virtual hosts; it doesn't seem to hurt.
${let
+
listen = concatMap getListen allHosts;
+
uniqueListen = uniqList {inputList = listen;};
+
directives = concatMapStrings (listen: "NameVirtualHost ${listenToString listen}\n") uniqueListen;
in optionalString (!version24) directives
}
${let
makeVirtualHost = vhost: ''
+
<VirtualHost ${concatStringsSep " " (map listenToString (getListen vhost))}>
${perServerConf false vhost}
</VirtualHost>
'';
···
message = "SSL is enabled for httpd, but sslServerCert and/or sslServerKey haven't been specified."; }
];
+
warnings = map (cfg: ''apache-httpd's port option is deprecated. Use listen = [{/*ip = "*"; */ port = ${toString cfg.port}";}]; instead'' ) (lib.filter (cfg: cfg.port != 0) allHosts);
+
users.extraUsers = optionalAttrs (mainCfg.user == "wwwrun") (singleton
{ name = "wwwrun";
group = mainCfg.group;
···
};
};
}
+23 -2
nixos/modules/services/web-servers/apache-httpd/per-server-options.nix
···
type = types.int;
default = 0;
description = ''
-
Port for the server. 0 means use the default port: 80 for http
-
and 443 for https (i.e. when enableSSL is set).
'';
};
enableSSL = mkOption {
···
type = types.int;
default = 0;
description = ''
+
Port for the server. Option will be removed, use <option>listen</option> instead.
+
'';
+
};
+
+
listen = mkOption {
+
type = types.listOf (types.submodule (
+
{
+
options = {
+
port = mkOption {
+
type = types.int;
+
description = "port to listen on";
+
};
+
ip = mkOption {
+
type = types.string;
+
default = "*";
+
description = "Ip to listen on. 0.0.0.0 for ipv4 only, * for all.";
+
};
+
};
+
} ));
+
description = ''
+
List of { /* ip: "*"; */ port = 80;} to listen on
'';
+
+
default = [];
};
enableSSL = mkOption {