2023-01-21 01:04:19 +00:00
|
|
|
# The reverse proxy of choice. Logs should be rotated weekly.
|
2023-01-12 13:22:55 +00:00
|
|
|
{ config, lib, pkgs, ... }:
|
|
|
|
|
|
|
|
{
|
|
|
|
# The main server where it will tie all of the services in one neat little
|
|
|
|
# place. Take note, the virtual hosts definition are all in their respective
|
|
|
|
# modules.
|
|
|
|
services.nginx = {
|
|
|
|
enable = true;
|
|
|
|
enableReload = true;
|
|
|
|
|
|
|
|
package = pkgs.nginxMainline;
|
|
|
|
|
|
|
|
recommendedOptimisation = true;
|
|
|
|
recommendedProxySettings = true;
|
|
|
|
recommendedTlsSettings = true;
|
2023-01-17 04:48:57 +00:00
|
|
|
|
2023-10-04 07:53:43 +00:00
|
|
|
# Some more server-sided compressions.
|
|
|
|
recommendedBrotliSettings = true;
|
|
|
|
recommendedGzipSettings = true;
|
|
|
|
recommendedZstdSettings = true;
|
|
|
|
|
2023-10-03 07:50:46 +00:00
|
|
|
proxyCachePath.apps = {
|
|
|
|
enable = true;
|
|
|
|
keysZoneName = "apps";
|
|
|
|
};
|
|
|
|
|
|
|
|
appendConfig = ''
|
|
|
|
worker_processes auto;
|
|
|
|
'';
|
|
|
|
|
2023-01-17 04:48:57 +00:00
|
|
|
# We're avoiding any service to be the default server especially that it
|
|
|
|
# could be used for enter a service with unencrypted HTTP. So we're setting
|
|
|
|
# up one with an unresponsive server response.
|
|
|
|
appendHttpConfig = ''
|
2023-10-03 07:50:46 +00:00
|
|
|
# https://docs.nginx.com/nginx/admin-guide/content-cache/content-caching/
|
|
|
|
proxy_cache_min_uses 5;
|
|
|
|
proxy_cache_valid 200 302 10m;
|
|
|
|
proxy_cache_valid 404 1m;
|
|
|
|
proxy_no_cache $http_pragma $http_authorization;
|
|
|
|
|
2023-01-17 04:48:57 +00:00
|
|
|
server {
|
2023-02-07 01:45:53 +00:00
|
|
|
listen 80 default_server;
|
2023-01-17 04:48:57 +00:00
|
|
|
listen [::]:80 default_server;
|
2023-02-07 01:45:53 +00:00
|
|
|
return 444;
|
2023-01-17 04:48:57 +00:00
|
|
|
}
|
|
|
|
'';
|
2023-01-12 13:22:55 +00:00
|
|
|
};
|
|
|
|
|
2023-01-21 01:04:19 +00:00
|
|
|
networking.firewall.allowedTCPPorts = [
|
|
|
|
80 # HTTP servers.
|
2023-02-11 07:21:18 +00:00
|
|
|
443 # HTTPS servers.
|
2023-01-21 01:04:19 +00:00
|
|
|
];
|
|
|
|
|
2023-01-12 13:22:55 +00:00
|
|
|
# Some fail2ban policies to apply for nginx.
|
|
|
|
services.fail2ban.jails = {
|
2023-07-14 06:41:58 +00:00
|
|
|
nginx-http-auth.settings = { enabled = true; };
|
|
|
|
nginx-botsearch.settings = { enabled = true; };
|
|
|
|
nginx-bad-request.settings = { enabled = true; };
|
2023-01-12 13:22:55 +00:00
|
|
|
};
|
2023-09-21 03:37:09 +00:00
|
|
|
|
|
|
|
# Generate a DH parameters for nginx-specific security configurations.
|
|
|
|
security.dhparams.params.nginx.bits = 4096;
|
2023-01-12 13:22:55 +00:00
|
|
|
}
|