aboutsummaryrefslogtreecommitdiffstats
path: root/roles/jails/01_ingress/templates/usr_local_etc_nginx_nginx.conf.j2
diff options
context:
space:
mode:
Diffstat (limited to 'roles/jails/01_ingress/templates/usr_local_etc_nginx_nginx.conf.j2')
-rw-r--r--roles/jails/01_ingress/templates/usr_local_etc_nginx_nginx.conf.j2123
1 files changed, 123 insertions, 0 deletions
diff --git a/roles/jails/01_ingress/templates/usr_local_etc_nginx_nginx.conf.j2 b/roles/jails/01_ingress/templates/usr_local_etc_nginx_nginx.conf.j2
new file mode 100644
index 0000000..3f853c5
--- /dev/null
+++ b/roles/jails/01_ingress/templates/usr_local_etc_nginx_nginx.conf.j2
@@ -0,0 +1,123 @@
+worker_processes auto;
+
+events {
+ worker_connections 1024;
+}
+
+http {
+ include mime.types;
+ default_type application/octet-stream;
+
+ sendfile on;
+ keepalive_timeout 65;
+
+ log_format vcombined '$host:$server_port '
+ '$remote_addr - $remote_user [$time_local] '
+ '"$request" $status $body_bytes_sent '
+ '"$http_referer" "$http_user_agent"';
+
+ access_log /var/log/nginx/access.log vcombined;
+
+ gzip on;
+ gzip_vary on;
+ gzip_min_length 512;
+ gzip_types
+ text/plain
+ text/css
+ application/json
+ application/javascript
+ application/xml
+ image/svg+xml;
+
+ server {
+ listen 80 default_server;
+ server_name _;
+
+ location / {
+ return 404;
+ }
+ }
+
+ {% for route in ingress_routes -%}
+ server {
+ listen 80;
+ listen [::]:80;
+ server_name {{ route.host }};
+
+{% if ssl_enabled %}
+ return 307 https://$host$request_uri;
+ }
+
+ server {
+ server_name {{ route.host }};
+ http2 on;
+
+ listen 443 ssl;
+ listen [::]:443 ssl;
+
+ # See https://ssl-config.mozilla.org/#server=nginx&version=1.28.0&config=intermediate&openssl=3.4.0&guideline=5.7
+ add_header Strict-Transport-Security "max-age=63072000" always;
+
+ # Common hardening headers
+ add_header X-Content-Type-Options nosniff always;
+ add_header X-Frame-Options DENY always;
+ add_header Referrer-Policy strict-origin-when-cross-origin always;
+ add_header Permissions-Policy interest-cohort=();
+
+ # Hide "Server: nginx/1.28.0" header
+ server_tokens off;
+
+ ssl_certificate /usr/local/etc/letsencrypt/live/{{ cert_name }}/fullchain.pem;
+ ssl_certificate_key /usr/local/etc/letsencrypt/live/{{ cert_name }}/privkey.pem;
+ include /usr/local/etc/letsencrypt/options-ssl-nginx.conf;
+ ssl_dhparam /usr/local/etc/letsencrypt/ssl-dhparams.pem;
+{% endif %}
+
+ {% if route.jail is defined -%}
+ {% for jail in jails if jail.name == route.jail -%}
+ location / {
+ proxy_pass http://{{ jail_lan_cidr | ipv4_nth(jail.num + jail_lan_offset | int) }}{% if route.port is defined %}:{{ route.port }}{% endif %};
+ proxy_set_header Host $host;
+ proxy_set_header X-Real-IP $remote_addr;
+ proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
+ proxy_set_header X-Forwarded-Proto $scheme;
+ {% if route.presets is defined -%}
+ {% set directives = [] -%}
+ {% for p in route.presets -%}
+ {% for d in nginx_presets[p] -%}
+ {% if d not in directives -%}{% set _ = directives.append(d) -%}{% endif -%}
+ {% endfor -%}
+ {% endfor -%}
+ {% for directive in directives -%}
+ {{ directive }};
+ {% endfor -%}
+ {% endif %}
+ }
+ {% endfor %}
+ {% elif route.redirect is defined -%}
+ return 307 https://{{ route.redirect }}$request_uri;
+ {% elif route.ip is defined -%}
+ location / {
+ proxy_pass http://{{ route.ip }}:{{ route.port }};
+ proxy_set_header Host $host;
+ proxy_set_header X-Real-IP $remote_addr;
+ proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
+ proxy_set_header X-Forwarded-Proto $scheme;
+
+ # TODO: these shouldn't configured for all ip:port proxies but Immich needs them
+ proxy_http_version 1.1;
+ proxy_set_header Connection "upgrade";
+ proxy_set_header Upgrade $http_upgrade;
+
+ # by default nginx times out connections in one minute
+ proxy_read_timeout 1d;
+ proxy_send_timeout 1d;
+ proxy_buffering off;
+ proxy_request_buffering off;
+
+ client_max_body_size 10G;
+ }
+ {% endif %}
+ }
+ {% endfor %}
+}