Commit Graph

347 Commits

Author SHA1 Message Date
Leona Maroni
33dc105554 nixos/nginx: set X-Forwarded-Server proxy header to hostname
X-Forwarded-Server represents the last server in a row of reverse proxies
in the common use, see:
- https://www.fastly.com/documentation/reference/http/http-headers/X-Forwarded-Server/
- https://httpd.apache.org/docs/2.4/mod/mod_proxy.html#x-headers
- https://docs.valsight.com/on-premise/latest/reverse-proxy

X-Forwarded-Host instead is the original request host.

This change adapts our NGINX module to the common use of this header.
2025-09-23 22:22:35 +02:00
dish
970dcca69c treewide: Fix links in module documentation 2025-08-25 12:55:11 -04:00
isabel
4ff7ee96bf nixos/nginx: add prependConfig options (#416411) 2025-08-16 18:55:51 +01:00
Christian Theune
2d0a489125 nixos/acme: improve scalability - reduce superfluous unit activations
The previous setup caused all renewal units to be triggered upon
ever so slight changes in config. In larger setups (100+ certificates)
adding a new certificate caused high system load and/or large memory
consumption issues. The memory issues are already a alleviated with
the locking mechanism. However, this then causes long delays upwards
of multiple minutes depending on individual runs and also caused
superfluous activations.

In this change we streamline the overall setup of units:

1. The unit that other services can depend upon is 'acme-{cert}.service'.
We call this the 'base unit'. As this one as `RemainAfterExit` set
the `acme-finished-{cert}` targets are not required any longer.

2. We now always generate initial self-signed certificates to simplify
the dependency structure. This deprecates the `preliminarySelfsigned`
option.

3. The `acme-order-renew-{cert}` service gets activated after the base
unit and services using certificates have started and performs all acme
interactions. When it finishes others services (like web servers) will
be notified through the `reloadServices` option or they can use
`wantedBy` and `after` dependencies if they implement their own reload
units.

The renewal timer also triggers this unit.

4. The timer unit is explicitly blocked from being started by s-t-c.

5. Permission management has been cleaned up a bit: there was an
   inconsistency between having the .lego files set to 600 vs 640
   on the exposed side. This is unified to 640 now.

6. Exempt the account target from being restarted by s-t-c. This will
   happen automatically if something relevant to the account changes.
2025-08-08 16:28:42 +02:00
teutat3s
e62971b005 nixos/nginx: sync with Mozilla Intermediate TLS configuration
- adds ssl_ecdh_curve, per https://github.com/mozilla/ssl-config-generator/issues/76
- removes ssl_stapling, after Let's Encrypt ended support for OCSP
  stapling https://letsencrypt.org/2024/12/05/ending-ocsp/, enabling ssl_stapling
  leads to warning log spam:
```
  ssl_stapling" ignored, no OCSP responder URL in the certificate "<cert-directory>
```
2025-07-26 14:26:28 +02:00
Wolfgang Walther
5a0711127c treewide: run nixfmt 1.0.0 2025-07-24 13:55:40 +02:00
Sandro Jäckel
0f964599a5 nixos/nginx: remove usage of recommendedZstdSettings and zstd settings duplication 2025-07-16 14:14:03 +02:00
Franz Pletz
db75f90103 nixos/nginx: remove recommendedZstdSettings, add experimental option
The zstd nginx module has known bugs and upstream is currently not
maintained. We should not recommend a buggy module and configuration
to our users since we are not maintaining the module either.
2025-07-03 17:41:22 +02:00
vdbe
b8d052a70d nixos/nginx: add prependConfig options
This is needed for example to load dynamic nginx modules.
Which need to be loaded before any `http` or `stream` blocks.
See: https://docs.nginx.com/nginx/admin-guide/dynamic-modules/dynamic-modules/#installing-and-loading-the-module
2025-06-13 12:21:18 +02:00
Maximilian Bosch
4a2a4193f9 nixos/nginx: fix type of mapHashBucketSize
While the default is indeed 32/64/128, the option accepts any `size`[1]
including values >128, as observed in a customer project.

[1] https://nginx.org/en/docs/http/ngx_http_map_module.html
2025-06-05 14:58:17 +02:00
Bert Proesmans
4c02c43a42 nixos/nginx: fix mkDefaultListenVhost mapping for unix sockets 2025-04-03 19:57:26 +00:00
Silvan Mosberger
374e6bcc40 treewide: Format all Nix files
Format all Nix files using the officially approved formatter,
making the CI check introduced in the previous commit succeed:

  nix-build ci -A fmt.check

This is the next step of the of the [implementation](https://github.com/NixOS/nixfmt/issues/153)
of the accepted [RFC 166](https://github.com/NixOS/rfcs/pull/166).

This commit will lead to merge conflicts for a number of PRs,
up to an estimated ~1100 (~33%) among the PRs with activity in the past 2
months, but that should be lower than what it would be without the previous
[partial treewide format](https://github.com/NixOS/nixpkgs/pull/322537).

Merge conflicts caused by this commit can now automatically be resolved while rebasing using the
[auto-rebase script](8616af08d9/maintainers/scripts/auto-rebase).

If you run into any problems regarding any of this, please reach out to the
[formatting team](https://nixos.org/community/teams/formatting/) by
pinging @NixOS/nix-formatting.
2025-04-01 20:10:43 +02:00
Maximilian Bosch
303bd80713 Merge: nixos/nginx: add locations."name".uwsgiPass option and use it (#346776) 2025-03-01 12:34:20 +01:00
Maximilian Bosch
2ad694fff9 nixos/nginx: remove custom HTTP_ header from recommendedUwsgiSettings
`uwsgi_pass` uses the uwsgi protocol instead of the HTTP protocol
(that's what `proxy_pass` is for). Also, the source IP is already
derived from the REMOTE_ADDR param that's specified by the uwsgi
defaults from nginx, similarily to how it's done for fcgi.

Hence, removing that since it seems not necessary (and perhaps even
wrong).
2025-02-21 13:48:07 +01:00
K900
17f38bc01d nixos/acme: disable rate limiting to fix the test
Sometimes the nginx reload service fires too fast so systemd kills it.
2025-01-19 12:19:00 +03:00
Sandro Jäckel
a810945475 nixos/nginx: default resolver.ipv6 to networking.enableIPv6 2024-12-25 03:58:32 +01:00
Sandro Jäckel
d1a28bbdb4 nixos/nginx: add locations."name".uwsgiPass and related options and use it 2024-12-11 01:07:02 +01:00
Silvan Mosberger
4f0dadbf38 treewide: format all inactive Nix files
After final improvements to the official formatter implementation,
this commit now performs the first treewide reformat of Nix files using it.
This is part of the implementation of RFC 166.

Only "inactive" files are reformatted, meaning only files that
aren't being touched by any PR with activity in the past 2 months.
This is to avoid conflicts for PRs that might soon be merged.
Later we can do a full treewide reformat to get the rest,
which should not cause as many conflicts.

A CI check has already been running for some time to ensure that new and
already-formatted files are formatted, so the files being reformatted here
should also stay formatted.

This commit was automatically created and can be verified using

    nix-build a08b3a4d19.tar.gz \
      --argstr baseRev b32a094368
    result/bin/apply-formatting $NIXPKGS_PATH
2024-12-10 20:26:33 +01:00
Sandro Jäckel
996f9e4f28 nixos/nginx: don't disable IPC
This also disables the memfd_create syscall which is required for
certain regex's when using pcre2.

see https://github.com/NixOS/nixpkgs/pull/355989#issuecomment-2506841275
2024-11-29 00:41:46 +01:00
K900
0453fe2395 {apache,caddy,nginx}: not "before" ACME certs using DNS validation (#336412) 2024-11-08 18:50:28 +03:00
ThinkChaos
3c2e82337d nixos/web-servers: assert ACME cert access via service user and groups
Allows giving access using SupplementaryGroups.
2024-11-07 20:19:12 -05:00
ThinkChaos
03122b43c8 nixos/nginx: not "before" ACME certs using DNS validation
Relax dependency with certs that are validated via DNS challenge since
we know the HTTP server is not required for that validation.
This allows marking the server's service as depending on the cert.
2024-11-07 20:19:12 -05:00
Ramses
3a1e2ab284 nginx: Create cryptographically secure htpasswd file (#347266) 2024-11-01 09:09:50 +01:00
Rafael Kraut
ef92d48263 nixos/nginx: use list for logrotate files attribute
This allows for easier extensibility.
2024-10-28 15:19:36 +01:00
Maximilian Bosch
e7d631432f Merge: nixos/nginx: create 127.0.0.1 alias for status page (#349536) 2024-10-24 12:49:10 +02:00
Ryan Horiguchi
449a963b0e nixos/nginx: create 127.0.0.1 alias for status page 2024-10-23 22:41:00 +02:00
Izorkin
b93bbf6406 nixos/nginx: remove rejectSSL assertion 2024-10-21 14:49:53 +03:00
Sandro Jäckel
a155c718d3 nixos/nginx: expand proxyResolveWhileRunning's description 2024-10-08 13:36:13 +02:00
Victor Engmark
7d3b47a0fa nginx: Create cryptographically secure htpasswd file
Requires the `htpasswd` command available from `pkgs.apacheHttpd`.
2024-10-08 23:14:26 +13:00
Victor Engmark
fef047eba5 nginx: Use placeholders which play nicely with Bash
`<` and `>` are redirection operators.
2024-10-08 23:09:47 +13:00
Maximilian Bosch
5ee80e8120 Merge: nixos/nginx: remove shortand from defaultText (#346767) 2024-10-06 17:13:51 +02:00
Sandro Jäckel
dd7ef21afc nixos/nginx: fix double slash in example 2024-10-06 03:45:51 +02:00
Sandro
b64b2d25c2 nixos/nginx: remove shortand from defaultText 2024-10-06 03:19:07 +02:00
Izorkin
d856c0374d nixos/nginx: add option typesHashMaxSize 2024-09-25 20:57:13 +03:00
Jörg Thalheim
5356420466 treewide: remove unused with statements from maintainer lists
$ find -type f -name '*.nix' -print0 | xargs -P "$(nproc)" -0 sed -i \
  -e 's!with lib.maintainers; \[ *\];![ ];!' \
  -e 's!with maintainers; \[ *\];![ ];!'
2024-07-29 10:06:20 +08:00
éclairevoyant
7d8742da87 treewide: fix mkEnableOption usage 2024-06-14 02:41:42 -04:00
Sandro Jäckel
f643e4fa5b nixos/tailscale-auth: fix enable option description 2024-06-02 22:30:42 +02:00
Pol Dellaiera
378c5c67ed Merge pull request #310348 from ehmry/nginx-validateConfigFile
nixos/nginx: add validateConfigFile option
2024-05-12 21:58:59 +02:00
Franz Pletz
b7d060d10d nixos/nginx: fix reference to acme cert hostname
The change introduced in #308303 refers to the virtualHosts attrset
key which can be any string. The servername is the actual primary
hostname used for the certificate.

This fixes use cases like:

    services.nginx.virualHosts.foobar.serverName = "my.fqdn.org";
2024-05-10 01:36:34 +02:00
Emery Hemingway
60c75135f8 nixos/nginx: add validateConfigFile option
Add an option to disable configuration file processing and
validation.
2024-05-09 16:48:26 +02:00
Lynn
a586e82ef6 nixos/nginx: don't add .well-known locations for acme when using DNS-01 challenge 2024-05-01 16:48:07 +02:00
Sandro Jäckel
8db512dae8 nixos/nginx: update ciphers list 2024-04-22 23:08:14 +10:00
Sandro
f417891699 Merge pull request #293954 from Dan-Theriault/refactor-tailscale-auth 2024-04-18 15:14:01 +02:00
Dan Theriault
3cf6c4ddb3 nixos/tailscale-auth: init module
This additional module allows the tailscale auth proxy to be configured
independently of nginx. The tailscale auth proxy works with both caddy
and traefik. All prior nginx/tailscale-auth options are retained as
aliases.
2024-04-16 19:06:08 -04:00
Kerstin Humm
d6e8934f38 nixos/nginx: allow for resolving IPv6 addresses only 2024-04-16 23:44:11 +02:00
stuebinm
6afb255d97 nixos: remove all uses of lib.mdDoc
these changes were generated with nixq 0.0.2, by running

  nixq ">> lib.mdDoc[remove] Argument[keep]" --batchmode nixos/**.nix
  nixq ">> mdDoc[remove] Argument[keep]" --batchmode nixos/**.nix
  nixq ">> Inherit >> mdDoc[remove]" --batchmode nixos/**.nix

two mentions of the mdDoc function remain in nixos/, both of which
are inside of comments.

Since lib.mdDoc is already defined as just id, this commit is a no-op as
far as Nix (and the built manual) is concerned.
2024-04-13 10:07:35 -07:00
Robert Schütz
1dd5f2b1f9 nixos/nginx: turn auth_request off for ACME challenge
This is e.g. necessary when using tailscale-nginx-auth.
2024-02-05 00:33:33 -08:00
Ryan Lahfa
6d8630efda Merge pull request #270270 from SuperSandro2000/nginx-fastopen
nixos/nginx: filter more options when listening has quic
2024-01-12 20:01:29 +01:00
Ryan Lahfa
3287441158 Merge pull request #275484 from Izorkin/update-nginx-http3
nixos/nginx: disable automatic advertise of HTTP/3 protocol support
2024-01-12 19:49:18 +01:00
Peder Bergebakken Sundt
f489e99576 Merge pull request #277925 from Izorkin/update-nginx-http2
nixos/nginx: use new variant of http2 option for angie package
2024-01-12 01:40:18 +01:00