]> Untitled Git - lemmy.git/blob - ansible/templates/nginx.conf
Fixing some front end pictshare to pictrs conversions.
[lemmy.git] / ansible / templates / nginx.conf
1 proxy_cache_path /var/cache/lemmy_frontend levels=1:2 keys_zone=lemmy_frontend_cache:10m max_size=100m                 use_temp_path=off;
2
3 server {
4     listen 80;
5     server_name {{ domain }};
6     location /.well-known/acme-challenge/ {
7         root /var/www/certbot;
8     }
9     location / {
10         return 301 https://$host$request_uri;
11     }
12 }
13
14 server {
15     listen 443 ssl http2;
16     server_name {{ domain }};
17
18     ssl_certificate /etc/letsencrypt/live/{{domain}}/fullchain.pem;
19     ssl_certificate_key /etc/letsencrypt/live/{{domain}}/privkey.pem;
20
21     # Various TLS hardening settings
22     # https://raymii.org/s/tutorials/Strong_SSL_Security_On_nginx.html
23     ssl_protocols TLSv1.2 TLSv1.3;
24     ssl_prefer_server_ciphers on;
25     ssl_ciphers 'ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-SHA384:ECDHE-RSA-AES256-SHA384:ECDHE-ECDSA-AES128-SHA256:ECDHE-RSA-AES128-SHA256';
26     ssl_session_timeout  10m;
27     ssl_session_cache shared:SSL:10m;
28     ssl_session_tickets off;
29     ssl_stapling on;
30     ssl_stapling_verify on;
31
32     # Hide nginx version
33     server_tokens off;
34
35     # Enable compression for JS/CSS/HTML bundle, for improved client load times.
36     # It might be nice to compress JSON, but leaving that out to protect against potential
37     # compression+encryption information leak attacks like BREACH.
38     gzip on;
39     gzip_types text/css application/javascript image/svg+xml;
40     gzip_vary on;
41
42     # Only connect to this site via HTTPS for the two years
43     add_header Strict-Transport-Security "max-age=63072000";
44
45     # Various content security headers
46     add_header Referrer-Policy "same-origin";
47     add_header X-Content-Type-Options "nosniff";
48     add_header X-Frame-Options "DENY";
49     add_header X-XSS-Protection "1; mode=block";
50
51     # Upload limit for pictshare
52     client_max_body_size 50M;
53
54     location / {
55         proxy_pass http://0.0.0.0:8536;
56         proxy_set_header X-Real-IP $remote_addr;
57         proxy_set_header Host $host;
58         proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
59
60         # WebSocket support
61         proxy_http_version 1.1;
62         proxy_set_header Upgrade $http_upgrade;
63         proxy_set_header Connection "upgrade";
64
65         # Proxy Cache
66         proxy_cache             lemmy_frontend_cache;
67         proxy_cache_use_stale   error timeout http_500 http_502 http_503 http_504;
68         proxy_cache_revalidate  on;
69         proxy_cache_lock        on;
70         proxy_cache_min_uses    5;
71     }    
72
73     location /pictrs/ {
74       proxy_pass http://0.0.0.0:8537/;
75       proxy_set_header X-Real-IP $remote_addr;
76       proxy_set_header Host $host;
77       proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
78
79       if ($request_uri ~ \.(?:ico|gif|jpe?g|png|webp|bmp|mp4)$) {
80         add_header Cache-Control "public, max-age=31536000, immutable";
81       }   
82     }
83
84     location /iframely/ {
85       proxy_pass http://0.0.0.0:8061/;
86       proxy_set_header X-Real-IP $remote_addr;
87       proxy_set_header Host $host;
88       proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
89     }
90 }
91
92 # Anonymize IP addresses
93 # https://www.supertechcrew.com/anonymizing-logs-nginx-apache/
94 map $remote_addr $remote_addr_anon {
95   ~(?P<ip>\d+\.\d+\.\d+)\.    $ip.0;
96   ~(?P<ip>[^:]+:[^:]+):       $ip::;
97   127.0.0.1                   $remote_addr;
98   ::1                         $remote_addr;
99   default                     0.0.0.0;
100 }
101 log_format main '$remote_addr_anon - $remote_user [$time_local] "$request" '
102 '$status $body_bytes_sent "$http_referer" "$http_user_agent"';
103 access_log /var/log/nginx/access.log main;