services.nginx: allow startup with ipv6 disabled (#21360)

currently services.nginx does not start up if `networking.enableIPv6 = false`
the commit changes the nginx behavior to handle this case accordingly.
The commit resolves #21308

authored by Felix Richter and committed by Robin Gloster d8478c79 9f6bd823

+7 -4
+7 -4
nixos/modules/services/web-servers/nginx/default.nix
··· 10 sslCertificateKey = "/var/lib/acme/${vhostName}/key.pem"; 11 }) 12 ) cfg.virtualHosts; 13 14 configFile = pkgs.writeText "nginx.conf" '' 15 user ${cfg.user} ${cfg.group}; ··· 84 ${optionalString cfg.statusPage '' 85 server { 86 listen 80; 87 - listen [::]:80; 88 89 server_name localhost; 90 ··· 92 stub_status on; 93 access_log off; 94 allow 127.0.0.1; 95 - allow ::1; 96 deny all; 97 } 98 } ··· 133 ${optionalString vhost.forceSSL '' 134 server { 135 listen 80 ${optionalString vhost.default "default"}; 136 - listen [::]:80 ${optionalString vhost.default "default"}; 137 138 server_name ${serverName} ${concatStringsSep " " vhost.serverAliases}; 139 ${acmeLocation} ··· 145 146 server { 147 listen ${listenString}; 148 - listen [::]:${listenString}; 149 150 server_name ${serverName} ${concatStringsSep " " vhost.serverAliases}; 151 ${acmeLocation}
··· 10 sslCertificateKey = "/var/lib/acme/${vhostName}/key.pem"; 11 }) 12 ) cfg.virtualHosts; 13 + enableIPv6 = config.networking.enableIPv6; 14 15 configFile = pkgs.writeText "nginx.conf" '' 16 user ${cfg.user} ${cfg.group}; ··· 85 ${optionalString cfg.statusPage '' 86 server { 87 listen 80; 88 + ${optionalString enableIPv6 "listen [::]:80;" } 89 90 server_name localhost; 91 ··· 93 stub_status on; 94 access_log off; 95 allow 127.0.0.1; 96 + ${optionalString enableIPv6 "allow ::1;"} 97 deny all; 98 } 99 } ··· 134 ${optionalString vhost.forceSSL '' 135 server { 136 listen 80 ${optionalString vhost.default "default"}; 137 + ${optionalString enableIPv6 138 + ''listen [::]:80 ${optionalString vhost.default "default"};'' 139 + } 140 141 server_name ${serverName} ${concatStringsSep " " vhost.serverAliases}; 142 ${acmeLocation} ··· 148 149 server { 150 listen ${listenString}; 151 + ${optionalString enableIPv6 "listen [::]:${listenString};"} 152 153 server_name ${serverName} ${concatStringsSep " " vhost.serverAliases}; 154 ${acmeLocation}