summaryrefslogtreecommitdiff
path: root/nginx/nginx.conf
blob: cae0ed505f9bd790bb60e37596c052a418b3402e (plain)
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
load_module modules/ngx_http_brotli_static_module.so;

user nginx;
worker_processes auto;
worker_rlimit_nofile 8192;
pid /run/nginx.pid;

events {
    worker_connections 4096;
}

http {
    include mime.types;
    default_type application/octet-stream;

    charset utf-8;

    sendfile on;
    tcp_nopush on;
    tcp_nodelay on;
    keepalive_timeout 65;
    types_hash_max_size 4096;
    server_tokens off;

    client_max_body_size 1k;
    client_body_buffer_size 1k;
    client_header_buffer_size 1k;
    large_client_header_buffers 4 4k;
    http2_max_field_size 4k;
    http2_max_header_size 16k;
    http2_recv_buffer_size 128k;

    client_body_timeout 30s;
    client_header_timeout 30s;
    send_timeout 30s;
    http2_recv_timeout 30s;

    http2_max_concurrent_streams 32;
    limit_conn_zone $binary_remote_addr zone=addr:10m;
    limit_conn addr 256;

    ssl_protocols TLSv1.2 TLSv1.3;
    ssl_ciphers ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-ECDSA-AES128-GCM-SHA256;
    ssl_prefer_server_ciphers on;

    ssl_certificate /etc/letsencrypt/live/grapheneos.org/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/grapheneos.org/privkey.pem;

    ssl_session_cache shared:SSL:10m;
    ssl_session_timeout 1d;
    ssl_session_tickets off;
    ssl_buffer_size 4k;

    ssl_trusted_certificate /etc/letsencrypt/live/grapheneos.org/chain.pem;
    ssl_stapling on;
    ssl_stapling_verify on;
    # maintained by certbot-ocsp-fetcher
    ssl_stapling_file /etc/nginx/ocsp-cache/grapheneos.org.der;

    access_log /var/log/nginx/access.log combined buffer=64k flush=1m;
    error_log /var/log/nginx/error.log;

    gzip_proxied any;
    gzip_vary on;

    if_modified_since before;

    map $http_cookie $preload_resources {
        "~*__Host-preload=1" "";
        default "</grapheneos.css?29>; rel=preload; as=style, </fonts/roboto_latin.woff2?20>; rel=preload; as=font; crossorigin, </fonts/roboto_bold_latin.woff2?20>; rel=preload; as=font; crossorigin, </mask-icon.svg>; rel=preload; as=image";
    }

    server {
        listen 80 backlog=4096;
        listen [::]:80 backlog=4096;
        server_name grapheneos.org www.grapheneos.org grapheneos.app www.grapheneos.app grapheneos.com www.grapheneos.com grapheneos.info www.grapheneos.info grapheneos.ovh www.grapheneos.ovh grapheneos.page www.grapheneos.page vanadium.app www.vanadium.app;

        root /var/empty;

        return 301 https://$host$request_uri;
    }

    server {
        listen 443 ssl http2 backlog=4096;
        listen [::]:443 ssl http2 backlog=4096;
        server_name www.grapheneos.org grapheneos.app www.grapheneos.app grapheneos.com www.grapheneos.com grapheneos.info www.grapheneos.info grapheneos.ovh www.grapheneos.ovh grapheneos.page www.grapheneos.page;

        root /var/empty;

        include snippets/security-headers.conf;

        return 301 https://grapheneos.org$request_uri;
    }

    server {
        listen 443 ssl http2;
        listen [::]:443 ssl http2;
        server_name vanadium.app www.vanadium.app;

        root /var/empty;

        include snippets/security-headers.conf;

        return 302 https://github.com/GrapheneOS/Vanadium;
    }

    server {
        listen 443 ssl http2;
        listen [::]:443 ssl http2;
        server_name grapheneos.org;

        root /var/www/html;
        error_page 403 =404 /404.html;
        error_page 404 /404.html;

        include snippets/security-headers.conf;
        gzip_static on;
        brotli_static on;

        if ($request_uri ~ ^/(.*)\.html$) {
            return 301 /$1;
        }

        if ($request_uri ~ (.*)//(.*)) {
            return 301 $1/$2;
        }

        if ($request_uri ~ ^(.*)/index$) {
            return 301 $1/;
        }

        # https://www.twipu.com/GrapheneOS doesn't handle links with fragments properly
        if ($request_uri ~ "^/(.*)%3Ca%20href=$") {
            return 301 https://grapheneos.org/$1;
        }

        location = /security.txt {
            return 301 /.well-known/security.txt;
        }

        location = /graphene.png {
            return 301 /logo.png;
        }

        location = /pdfviewer_privacy_policy {
            return 301 /pdfviewer-privacy-policy;
        }

        location = /safari_pinned_tab_icon.svg {
            return 301 /mask-icon.svg;
        }

        location = /safari-pinned-tab-icon.svg {
            return 301 /mask-icon.svg;
        }

        location = /bitcoin_address.png {
            return 301 /bitcoin-donation.png;
        }

        location = /bitcoin-address.png {
            return 301 /bitcoin-donation.png;
        }

        # mangled backlinks to /install
        location = /installMinimal {
            return 301 /install/;
        }

        location = /web-install {
            return 301 /install/web;
        }

        location = /install-web {
            return 301 /install/web;
        }

        location = /cli/install {
            return 301 /install/cli;
        }

        location = /web/install {
            return 301 /install/web;
        }

        location = /LICENSE {
            return 301 /LICENSE.txt;
        }

        location = /mstile-150x150.png {
            return 301 /mstile/150x150.png;
        }

        location = /mstile-310x310.png {
            return 301 /mstile/310x310.png;
        }

        location = /mstile-70x70.png {
            return 301 /mstile/70x70.png;
        }

        location = /mstile-310x150.png {
            return 301 /mstile/310x150.png;
        }

        location = /generate_204 {
            return 301 /faq#default-connections;
        }

        location = /404 {
            internal;
            include snippets/security-headers.conf;
            include snippets/preload.conf;
        }

        location = /404.html {
            internal;
            include snippets/security-headers.conf;
            include snippets/preload.conf;
        }

        # broken link (now fixed) on https://noagendaphone.com/ with UTF-8 replacement character
        location ~ "^/\xEF\xBF\xBC$" {
            return 301 /;
        }

        location ~ "\.(ico|webmanifest)$" {
            include snippets/security-headers.conf;
            add_header Cache-Control "public, max-age=604800";
        }

        location ~ "\.(css|js|mjs|svg)$" {
            include snippets/security-headers.conf;
            add_header Cache-Control "public, max-age=31536000";
        }

        location ~ "\.(png|woff2)$" {
            include snippets/security-headers.conf;
            add_header Cache-Control "public, max-age=31536000";
            gzip_static off;
            brotli_static off;
        }

        location ~ "\.(atom|json|pdf|txt|xml)$" {
            include snippets/security-headers.conf;
            add_header Cache-Control "public, max-age=1800";
        }

        location ~ "\.(br|gz)$" {
            internal;
        }

        location = /install/web {
            include snippets/security-headers-base.conf;
            add_header Content-Security-Policy "default-src 'none'; child-src 'self'; connect-src 'self' https://releases.grapheneos.org/; font-src 'self'; img-src 'self'; manifest-src 'self'; script-src 'self'; style-src 'self'; form-action 'none'; frame-ancestors 'none'; block-all-mixed-content; base-uri 'none'" always;
            add_header Permissions-Policy "accelerometer=(), ambient-light-sensor=(), autoplay=(), battery=(), camera=(), display-capture=(), document-domain=(), encrypted-media=(), fullscreen=(), geolocation=(), gyroscope=(), magnetometer=(), microphone=(), midi=(), payment=(), picture-in-picture=(), publickey-credentials-get=(), screen-wake-lock=(), sync-xhr=(), xr-spatial-tracking=()" always;
            add_header Cache-Control "public, no-cache";
            include snippets/preload.conf;
            try_files $uri.html =404;
        }

        location / {
            include snippets/security-headers.conf;
            add_header Cache-Control "public, no-cache";
            include snippets/preload.conf;
            try_files $uri $uri.html $uri/ =404;
        }
    }

    server {
        listen 80;
        listen [::]:80;
        server_name mta-sts.grapheneos.org mta-sts.mail.grapheneos.org mta-sts.grapheneos.app mta-sts.grapheneos.com mta-sts.grapheneos.info mta-sts.grapheneos.ovh mta-sts.grapheneos.page mta-sts.vanadium.app;

        root /var/empty;

        return 301 https://$host$request_uri;
    }

    server {
        listen 443 ssl http2;
        listen [::]:443 ssl http2;
        server_name mta-sts.grapheneos.org mta-sts.mail.grapheneos.org mta-sts.grapheneos.app mta-sts.grapheneos.com mta-sts.grapheneos.info mta-sts.grapheneos.ovh mta-sts.grapheneos.page mta-sts.vanadium.app;

        root /var/www/mta-sts;

        include snippets/security-headers.conf;
    }

    server {
        listen 127.0.0.1:81;
        listen [::1]:81;

        location /nginx_status {
            stub_status;
            access_log off;
        }
    }
}