Skip to content

Commit 303bd80

Browse files
authored
Merge: nixos/nginx: add locations."name".uwsgiPass option and use it (#346776)
2 parents cc65a31 + 2ad694f commit 303bd80

File tree

3 files changed

+74
-2
lines changed

3 files changed

+74
-2
lines changed

nixos/modules/services/mail/mailman.nix

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -447,7 +447,7 @@ in {
447447
enable = lib.mkDefault true;
448448
virtualHosts = lib.genAttrs cfg.webHosts (webHost: {
449449
locations = {
450-
${cfg.serve.virtualRoot}.extraConfig = "uwsgi_pass unix:/run/mailman-web.socket;";
450+
${cfg.serve.virtualRoot}.uwsgiPass = "unix:/run/mailman-web.socket";
451451
"${lib.removeSuffix "/" cfg.serve.virtualRoot}/static/".alias = webSettings.STATIC_ROOT + "/";
452452
};
453453
});

nixos/modules/services/web-servers/nginx/default.nix

Lines changed: 54 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ let
9696
REDIRECT_STATUS = "200";
9797
};
9898

99-
recommendedProxyConfig = pkgs.writeText "nginx-recommended-proxy-headers.conf" ''
99+
recommendedProxyConfig = pkgs.writeText "nginx-recommended-proxy_set_header-headers.conf" ''
100100
proxy_set_header Host $host;
101101
proxy_set_header X-Real-IP $remote_addr;
102102
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
@@ -240,6 +240,14 @@ let
240240
include ${recommendedProxyConfig};
241241
''}
242242
243+
${optionalString cfg.recommendedUwsgiSettings ''
244+
uwsgi_connect_timeout ${cfg.uwsgiTimeout};
245+
uwsgi_send_timeout ${cfg.uwsgiTimeout};
246+
uwsgi_read_timeout ${cfg.uwsgiTimeout};
247+
uwsgi_param HTTP_CONNECTION "";
248+
include ${cfg.package}/conf/uwsgi_params;
249+
''}
250+
243251
${optionalString (cfg.mapHashBucketSize != null) ''
244252
map_hash_bucket_size ${toString cfg.mapHashBucketSize};
245253
''}
@@ -444,6 +452,13 @@ let
444452
proxy_set_header Upgrade $http_upgrade;
445453
proxy_set_header Connection $connection_upgrade;
446454
''}
455+
${optionalString (config.uwsgiPass != null && !cfg.uwsgiResolveWhileRunning)
456+
"uwsgi_pass ${config.uwsgiPass};"
457+
}
458+
${optionalString (config.uwsgiPass != null && cfg.uwsgiResolveWhileRunning) ''
459+
set $nix_proxy_target "${config.uwsgiPass}";
460+
uwsgi_pass $nix_proxy_target;
461+
''}
447462
${concatStringsSep "\n"
448463
(mapAttrsToList (n: v: ''fastcgi_param ${n} "${v}";'')
449464
(optionalAttrs (config.fastcgiParams != {})
@@ -455,6 +470,7 @@ let
455470
${optionalString (config.return != null) "return ${toString config.return};"}
456471
${config.extraConfig}
457472
${optionalString (config.proxyPass != null && config.recommendedProxySettings) "include ${recommendedProxyConfig};"}
473+
${optionalString (config.uwsgiPass != null && config.recommendedUwsgiSettings) "include ${cfg.package}/conf/uwsgi_params;"}
458474
${mkBasicAuth "sublocation" config}
459475
}
460476
'') (sortProperties (mapAttrsToList (k: v: v // { location = k; }) locations)));
@@ -555,6 +571,23 @@ in
555571
'';
556572
};
557573

574+
recommendedUwsgiSettings = mkOption {
575+
default = false;
576+
type = types.bool;
577+
description = ''
578+
Whether to enable recommended uwsgi settings if a vhost does not specify the option manually.
579+
'';
580+
};
581+
582+
uwsgiTimeout = mkOption {
583+
type = types.str;
584+
default = "60s";
585+
example = "20s";
586+
description = ''
587+
Change the uwsgi related timeouts in recommendedUwsgiSettings.
588+
'';
589+
};
590+
558591
defaultListen = mkOption {
559592
type = with types; listOf (submodule {
560593
options = {
@@ -864,6 +897,16 @@ in
864897
'';
865898
};
866899

900+
uwsgiResolveWhileRunning = mkOption {
901+
type = types.bool;
902+
default = false;
903+
description = ''
904+
Resolves domains of uwsgi targets at runtime
905+
and not only at start, you have to set
906+
services.nginx.resolver, too.
907+
'';
908+
};
909+
867910
mapHashBucketSize = mkOption {
868911
type = types.nullOr (types.enum [ 32 64 128 ]);
869912
default = null;
@@ -1161,6 +1204,16 @@ in
11611204
'';
11621205
}
11631206

1207+
{
1208+
assertion = all (host:
1209+
all (location: !(location.proxyPass != null && location.uwsgiPass != null)) (attrValues host.locations))
1210+
(attrValues virtualHosts);
1211+
message = ''
1212+
Options services.nginx.service.virtualHosts.<name>.proxyPass and
1213+
services.nginx.virtualHosts.<name>.uwsgiPass are mutually exclusive.
1214+
'';
1215+
}
1216+
11641217
{
11651218
assertion = cfg.package.pname != "nginxQuic" && cfg.package.pname != "angieQuic" -> !(cfg.enableQuicBPF);
11661219
message = ''

nixos/modules/services/web-servers/nginx/location-options.nix

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,16 @@ with lib;
5353
'';
5454
};
5555

56+
uwsgiPass = mkOption {
57+
type = types.nullOr types.str;
58+
default = null;
59+
example = "unix:/run/example/example.sock";
60+
description = ''
61+
Adds uwsgi_pass directive and sets recommended proxy headers if
62+
recommendedUwsgiSettings is enabled.
63+
'';
64+
};
65+
5666
index = mkOption {
5767
type = types.nullOr types.str;
5868
default = null;
@@ -134,5 +144,14 @@ with lib;
134144
Enable recommended proxy settings.
135145
'';
136146
};
147+
148+
recommendedUwsgiSettings = mkOption {
149+
type = types.bool;
150+
default = config.services.nginx.recommendedUwsgiSettings;
151+
defaultText = literalExpression "config.services.nginx.recommendedUwsgiSettings";
152+
description = ''
153+
Enable recommended uwsgi settings.
154+
'';
155+
};
137156
};
138157
}

0 commit comments

Comments
 (0)