aboutsummaryrefslogtreecommitdiff
path: root/roles/host/templates/nginx.conf.j2
blob: 7360caec83b5a1854bb7e74e5cc5f5d7a82f53b6 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
user nginx;
worker_processes auto;
worker_rlimit_nofile 8192;
error_log /var/log/nginx/error.log notice;
pid /run/nginx.pid;

events {
    worker_connections 4096;
}

http {
    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';

    access_log  /var/log/nginx/access.log  main;

    sendfile            on;
    tcp_nopush          on;
    keepalive_timeout   65;
    types_hash_max_size 4096;

    include             /etc/nginx/mime.types;
    default_type        application/octet-stream;

    # Modern SSL configuration
    ssl_protocols TLSv1.2 TLSv1.3;
    ssl_ciphers ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:DHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384;
    ssl_prefer_server_ciphers on;
    ssl_session_cache shared:SSL:10m;
    ssl_session_timeout 1d;
    ssl_session_tickets off;

    # Redirect all HTTP traffic to HTTPS
    server {
        listen 80 default_server;
        server_name _;
        return 301 https://$host$request_uri;
    }

{% for name, config in containers.items() %}
{% if config.web_subdomain is defined %}
    server {
        listen 443 ssl;         # TCP for HTTP/1.1 & HTTP/2
        listen 443 quic;        # UDP for HTTP/3 QUIC
        http2 on;               # Enable HTTP/2 over TCP

        server_name {{ config.web_subdomain }}.{{ vault_public_domain }};

        # Nginx reads them natively, no combining needed
        ssl_certificate /etc/letsencrypt/live/{{ vault_public_domain }}/fullchain.pem;
        ssl_certificate_key /etc/letsencrypt/live/{{ vault_public_domain }}/privkey.pem;

        # Advertise HTTP/3 availability to browsers
        add_header Alt-Svc 'h3=":443"; ma=2592000' always;

        location / {
            proxy_pass http://{{ config.ip }}:80;
            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 https;
        }
    }
{% endif %}
{% endfor %}
}