diff --git a/nixos/modules/services/web-servers/apache-httpd/default.nix b/nixos/modules/services/web-servers/apache-httpd/default.nix index 5950a6116b70..a2474fcfa6f2 100644 --- a/nixos/modules/services/web-servers/apache-httpd/default.nix +++ b/nixos/modules/services/web-servers/apache-httpd/default.nix @@ -110,25 +110,20 @@ let } ++ cfg.extraModules; - loggingConf = ( - if cfg.logFormat != "none" then - '' - ErrorLog ${cfg.logDir}/error.log + loggingConf = '' + ErrorLog ${if cfg.logFormat != "none" then "${cfg.logDir}/error.log" else "/dev/null"} + ${optionalString (cfg.logLevel != null) "LogLevel ${cfg.logLevel}"} - LogLevel notice + LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined + LogFormat "%h %l %u %t \"%r\" %>s %b" common + LogFormat "%{Referer}i -> %U" referer + LogFormat "%{User-agent}i" agent + ${optionalString ( + cfg.logFormat == "custom" + ) "LogFormat ${lib.strings.escapeNixString cfg.customLogFormat} custom"} - LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined - LogFormat "%h %l %u %t \"%r\" %>s %b" common - LogFormat "%{Referer}i -> %U" referer - LogFormat "%{User-agent}i" agent - - CustomLog ${cfg.logDir}/access.log ${cfg.logFormat} - '' - else - '' - ErrorLog /dev/null - '' - ); + CustomLog ${cfg.logDir}/access.log ${cfg.logFormat} + ''; browserHacks = '' @@ -582,12 +577,67 @@ in }; logFormat = mkOption { - type = types.str; + type = types.enum [ + "combined" + "common" + "referer" + "agent" + "custom" + "none" + ]; default = "common"; - example = "combined"; + example = "custom"; description = '' - Log format for log files. Possible values are: combined, common, referer, agent, none. - See for more details. + Selects the access log format written to log files. + + The values `combined`, `common`, `referer`, and `agent` correspond to predefined Apache HTTPD log formats. + Setting the value to `custom` enables the use of a user-defined format string specified via `customLogFormat`. + The value `none` disables access logging entirely. + + Further details on Apache log formats are available at . + ''; + }; + + customLogFormat = mkOption { + type = types.str; + default = null; + example = ''%{X-Forwarded-For}i %l %u %t \"%r\" %>s %b''; + description = '' + Defines a custom Apache HTTPD access log format string. + + This option is only consulted when `logFormat` is set to `custom`. + The value must be a valid Apache `LogFormat` specification and will be registered under the symbolic name `custom`. + + See for the formal definition of log format directives. + ''; + }; + + logLevel = mkOption { + type = + with types; + nullOr (enum [ + "emerg" + "alert" + "crit" + "error" + "warn" + "notice" + "info" + "debug" + "trace1" + "trace2" + "trace3" + "trace4" + "trace5" + "trace6" + "trace7" + "trace8" + ]); + default = "notice"; + example = "crit"; + description = '' + Controls the verbosity of the ErrorLog. + See for more details. ''; };