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