diff --git a/modules/services/web-servers/apache-httpd/default.nix b/modules/services/web-servers/apache-httpd/default.nix
index 9ceb66a85a0a..1729850421a3 100644
--- a/modules/services/web-servers/apache-httpd/default.nix
+++ b/modules/services/web-servers/apache-httpd/default.nix
@@ -8,6 +8,8 @@ let
httpd = mainCfg.package;
+ version24 = !versionOlder httpd.version "2.4";
+
httpdConf = mainCfg.configFile;
php = pkgs.php.override { apacheHttpd = httpd; };
@@ -101,7 +103,8 @@ let
"auth_basic" "auth_digest"
# Authentication: is the user who he claims to be?
- "authn_file" "authn_dbm" "authn_anon" "authn_alias"
+ "authn_file" "authn_dbm" "authn_anon"
+ (if version24 then "authn_core" else "authn_alias")
# Authorization: is the user allowed access?
"authz_user" "authz_groupfile" "authz_host"
@@ -113,11 +116,31 @@ let
"vhost_alias" "negotiation" "dir" "imagemap" "actions" "speling"
"userdir" "alias" "rewrite" "proxy" "proxy_http"
]
+ ++ optionals version24 [
+ "mpm_${mainCfg.multiProcessingModule}"
+ "authz_core"
+ "unixd"
+ ]
++ (if mainCfg.multiProcessingModule == "prefork" then [ "cgi" ] else [ "cgid" ])
++ optional enableSSL "ssl"
++ extraApacheModules;
+ allDenied = if version24 then ''
+ Require all denied
+ '' else ''
+ Order deny,allow
+ Deny from all
+ '';
+
+ allGranted = if version24 then ''
+ Require all granted
+ '' else ''
+ Order allow,deny
+ Allow from all
+ '';
+
+
loggingConf = ''
ErrorLog ${mainCfg.logDir}/error_log
@@ -186,8 +209,7 @@ let
Options Indexes FollowSymLinks
AllowOverride None
- Order allow,deny
- Allow from all
+ ${allGranted}
'';
@@ -241,12 +263,10 @@ let
AllowOverride FileInfo AuthConfig Limit Indexes
Options MultiViews Indexes SymLinksIfOwnerMatch IncludesNoExec
- Order allow,deny
- Allow from all
+ ${allGranted}
- Order deny,allow
- Deny from all
+ ${allDenied}
@@ -268,8 +288,7 @@ let
Alias ${elem.urlPath} ${elem.dir}/
Options +Indexes
- Order allow,deny
- Allow from all
+ ${allGranted}
AllowOverride All
'';
@@ -286,6 +305,10 @@ let
ServerRoot ${httpd}
+ ${optionalString version24 ''
+ DefaultRuntimeDir ${mainCfg.stateDir}/runtime
+ ''}
+
PidFile ${mainCfg.stateDir}/httpd.pid
${optionalString (mainCfg.multiProcessingModule != "prefork") ''
@@ -321,8 +344,7 @@ let
AddHandler type-map var
- Order allow,deny
- Deny from all
+ ${allDenied}
${mimeConf}
@@ -340,16 +362,14 @@ let
Options FollowSymLinks
AllowOverride None
- Order deny,allow
- Deny from all
+ ${allDenied}
# But do allow access to files in the store so that we don't have
# to generate clauses for every generated file that we
# want to serve.
- Order allow,deny
- Allow from all
+ ${allGranted}
# Generate directives for the main server.
@@ -359,7 +379,8 @@ let
${let
ports = map getPort allHosts;
uniquePorts = uniqList {inputList = ports;};
- in concatMapStrings (port: "NameVirtualHost *:${toString port}\n") uniquePorts
+ directives = concatMapStrings (port: "NameVirtualHost *:${toString port}\n") uniquePorts;
+ in optionalString (!version24) directives
}
${let
@@ -620,6 +641,10 @@ in
''
mkdir -m 0750 -p ${mainCfg.stateDir}
chown root.${mainCfg.group} ${mainCfg.stateDir}
+ ${optionalString version24 ''
+ mkdir -m 0750 -p "${mainCfg.stateDir}/runtime"
+ chown root.${mainCfg.group} "${mainCfg.stateDir}/runtime"
+ ''}
mkdir -m 0700 -p ${mainCfg.logDir}
${optionalString (mainCfg.documentRoot != null)