|
94 | 94 | REDIRECT_STATUS = "200"; |
95 | 95 | }; |
96 | 96 |
|
97 | | - recommendedProxyConfig = pkgs.writeText "nginx-recommended-proxy-headers.conf" '' |
| 97 | + recommendedProxyConfig = pkgs.writeText "nginx-recommended-proxy_set_header-headers.conf" '' |
98 | 98 | proxy_set_header Host $host; |
99 | 99 | proxy_set_header X-Real-IP $remote_addr; |
100 | 100 | proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; |
101 | 101 | proxy_set_header X-Forwarded-Proto $scheme; |
102 | 102 | proxy_set_header X-Forwarded-Host $host; |
103 | 103 | proxy_set_header X-Forwarded-Server $host; |
104 | 104 | ''; |
| 105 | + recommendedUwsgiConfig = pkgs.writeText "nginx-recommended-uwsgi_param-headers.conf" '' |
| 106 | + uwsgi_param HTTP_HOST $host; |
| 107 | + uwsgi_param HTTP_X_REAL_IP $remote_addr; |
| 108 | + uwsgi_param HTTP_X_FORWARDED_FOR $proxy_add_x_forwarded_for; |
| 109 | + uwsgi_param HTTP_X_FORWARDED_PROTO $scheme; |
| 110 | + uwsgi_param HTTP_X_FORWARDED_HOST $host; |
| 111 | + uwsgi_param HTTP_X_FORWARDED_SERVER $host; |
| 112 | + ''; |
105 | 113 |
|
106 | 114 | proxyCachePathConfig = concatStringsSep "\n" (mapAttrsToList (name: proxyCachePath: '' |
107 | 115 | proxy_cache_path ${concatStringsSep " " [ |
|
238 | 246 | include ${recommendedProxyConfig}; |
239 | 247 | ''} |
240 | 248 |
|
| 249 | + ${optionalString cfg.recommendedUwsgiSettings '' |
| 250 | + uwsgi_connect_timeout ${cfg.uwsgiTimeout}; |
| 251 | + uwsgi_send_timeout ${cfg.uwsgiTimeout}; |
| 252 | + uwsgi_read_timeout ${cfg.uwsgiTimeout}; |
| 253 | + uwsgi_param HTTP_CONNECTION ""; |
| 254 | + include ${cfg.package}/conf/uwsgi_params; |
| 255 | + include ${recommendedUwsgiConfig}; |
| 256 | + ''} |
| 257 | +
|
241 | 258 | ${optionalString (cfg.mapHashBucketSize != null) '' |
242 | 259 | map_hash_bucket_size ${toString cfg.mapHashBucketSize}; |
243 | 260 | ''} |
|
442 | 459 | proxy_set_header Upgrade $http_upgrade; |
443 | 460 | proxy_set_header Connection $connection_upgrade; |
444 | 461 | ''} |
| 462 | + ${optionalString (config.uwsgiPass != null && !cfg.uwsgiResolveWhileRunning) |
| 463 | + "uwsgi_pass ${config.uwsgiPass};" |
| 464 | + } |
| 465 | + ${optionalString (config.uwsgiPass != null && cfg.uwsgiResolveWhileRunning) '' |
| 466 | + set $nix_proxy_target "${config.uwsgiPass}"; |
| 467 | + uwsgi_pass $nix_proxy_target; |
| 468 | + ''} |
445 | 469 | ${concatStringsSep "\n" |
446 | 470 | (mapAttrsToList (n: v: ''fastcgi_param ${n} "${v}";'') |
447 | 471 | (optionalAttrs (config.fastcgiParams != {}) |
|
453 | 477 | ${optionalString (config.return != null) "return ${toString config.return};"} |
454 | 478 | ${config.extraConfig} |
455 | 479 | ${optionalString (config.proxyPass != null && config.recommendedProxySettings) "include ${recommendedProxyConfig};"} |
| 480 | + ${optionalString (config.uwsgiPass != null && config.recommendedUwsgiSettings) "include ${cfg.package}/conf/uwsgi_params; include ${recommendedUwsgiConfig};"} |
456 | 481 | ${mkBasicAuth "sublocation" config} |
457 | 482 | } |
458 | 483 | '') (sortProperties (mapAttrsToList (k: v: v // { location = k; }) locations))); |
|
553 | 578 | ''; |
554 | 579 | }; |
555 | 580 |
|
| 581 | + recommendedUwsgiSettings = mkOption { |
| 582 | + default = false; |
| 583 | + type = types.bool; |
| 584 | + description = '' |
| 585 | + Whether to enable recommended uwsgi settings if a vhost does not specify the option manually. |
| 586 | + ''; |
| 587 | + }; |
| 588 | + |
| 589 | + uwsgiTimeout = mkOption { |
| 590 | + type = types.str; |
| 591 | + default = "60s"; |
| 592 | + example = "20s"; |
| 593 | + description = '' |
| 594 | + Change the uwsgi related timeouts in recommendedUwsgiSettings. |
| 595 | + ''; |
| 596 | + }; |
| 597 | + |
556 | 598 | defaultListen = mkOption { |
557 | 599 | type = with types; listOf (submodule { |
558 | 600 | options = { |
|
859 | 901 | ''; |
860 | 902 | }; |
861 | 903 |
|
| 904 | + uwsgiResolveWhileRunning = mkOption { |
| 905 | + type = types.bool; |
| 906 | + default = false; |
| 907 | + description = '' |
| 908 | + Resolves domains of uwsgi targets at runtime |
| 909 | + and not only at start, you have to set |
| 910 | + services.nginx.resolver, too. |
| 911 | + ''; |
| 912 | + }; |
| 913 | + |
862 | 914 | mapHashBucketSize = mkOption { |
863 | 915 | type = types.nullOr (types.enum [ 32 64 128 ]); |
864 | 916 | default = null; |
@@ -1163,6 +1215,16 @@ in |
1163 | 1215 | ''; |
1164 | 1216 | } |
1165 | 1217 |
|
| 1218 | + { |
| 1219 | + assertion = all (host: |
| 1220 | + all (location: !(location.proxyPass != null && location.uwsgiPass != null)) (attrValues host.locations)) |
| 1221 | + (attrValues virtualHosts); |
| 1222 | + message = '' |
| 1223 | + Options services.nginx.service.virtualHosts.<name>.proxyPass and |
| 1224 | + services.nginx.virtualHosts.<name>.uwsgiPass are mutually exclusive. |
| 1225 | + ''; |
| 1226 | + } |
| 1227 | + |
1166 | 1228 | { |
1167 | 1229 | assertion = cfg.package.pname != "nginxQuic" && cfg.package.pname != "angieQuic" -> !(cfg.enableQuicBPF); |
1168 | 1230 | message = '' |
|
0 commit comments