diff options
author | Susan Potter <me@susanpotter.net> | 2017-02-28 09:15:20 -0600 |
---|---|---|
committer | Susan Potter <me@susanpotter.net> | 2017-02-28 09:36:56 -0600 |
commit | 251b9ca0e77963c48d9c198cec964f7a1cd91d4a (patch) | |
tree | 6b0ef40ed516af13694ce43d05a7dadc21dea195 | |
parent | e0b04b4c37cbdad66491f5ac018166a6d1e100e2 (diff) | |
download | nixpkgs-251b9ca0e77963c48d9c198cec964f7a1cd91d4a.tar nixpkgs-251b9ca0e77963c48d9c198cec964f7a1cd91d4a.tar.gz nixpkgs-251b9ca0e77963c48d9c198cec964f7a1cd91d4a.tar.bz2 nixpkgs-251b9ca0e77963c48d9c198cec964f7a1cd91d4a.tar.lz nixpkgs-251b9ca0e77963c48d9c198cec964f7a1cd91d4a.tar.xz nixpkgs-251b9ca0e77963c48d9c198cec964f7a1cd91d4a.tar.zst nixpkgs-251b9ca0e77963c48d9c198cec964f7a1cd91d4a.zip |
nginx service: add commonHttpConfig option
-rw-r--r-- | nixos/modules/services/web-servers/nginx/default.nix | 20 | ||||
-rw-r--r-- | nixos/tests/nginx.nix | 42 |
2 files changed, 62 insertions, 0 deletions
diff --git a/nixos/modules/services/web-servers/nginx/default.nix b/nixos/modules/services/web-servers/nginx/default.nix index 6bc7192963d..548467ae785 100644 --- a/nixos/modules/services/web-servers/nginx/default.nix +++ b/nixos/modules/services/web-servers/nginx/default.nix @@ -87,6 +87,8 @@ let server_tokens ${if cfg.serverTokens then "on" else "off"}; + ${cfg.commonHttpConfig} + ${vhosts} ${optionalString cfg.statusPage '' @@ -275,6 +277,24 @@ in ''; }; + commonHttpConfig = mkOption { + type = types.lines; + default = ""; + example = '' + resolver 127.0.0.1 valid=5s; + + log_format myformat '$remote_addr - $remote_user [$time_local] ' + '"$request" $status $body_bytes_sent ' + '"$http_referer" "$http_user_agent"'; + ''; + description = '' + With nginx you must provide common http context definitions before + they are used, e.g. log_format, resolver, etc. inside of server + or location contexts. Use this attribute to set these definitions + at the appropriate location. + ''; + }; + httpConfig = mkOption { type = types.lines; default = ""; diff --git a/nixos/tests/nginx.nix b/nixos/tests/nginx.nix new file mode 100644 index 00000000000..c2beb5590ef --- /dev/null +++ b/nixos/tests/nginx.nix @@ -0,0 +1,42 @@ +# verifies: +# 1. nginx generates config file with shared http context definitions above +# generated virtual hosts config. + +import ./make-test.nix ({ pkgs, ...} : { + name = "jenkins"; + meta = with pkgs.stdenv.lib.maintainers; { + maintainers = [ mbbx6spp ]; + }; + + nodes = { + webserver = + { config, pkgs, ... }: + { services.nginx.enable = true; + services.nginx.commonHttpConfig = '' + log_format ceeformat '@cee: {"status":"$status",' + '"request_time":$request_time,' + '"upstream_response_time":$upstream_response_time,' + '"pipe":"$pipe","bytes_sent":$bytes_sent,' + '"connection":"$connection",' + '"remote_addr":"$remote_addr",' + '"host":"$host",' + '"timestamp":"$time_iso8601",' + '"request":"$request",' + '"http_referer":"$http_referer",' + '"upstream_addr":"$upstream_addr"}'; + ''; + services.nginx.virtualHosts."0.my.test" = { + extraConfig = '' + access_log syslog:server=unix:/dev/log,facility=user,tag=mytag,severity=info ceeformat; + ''; + }; + }; + }; + + testScript = '' + startAll; + + $webserver->waitForUnit("nginx"); + $webserver->waitForOpenPort("80"); + ''; +}) |