1 limit_req_zone $binary_remote_addr zone=lemmy_ratelimit:10m rate=1r/s;
5 server_name {{ domain }};
6 location /.well-known/acme-challenge/ {
10 return 301 https://$host$request_uri;
16 server_name {{ domain }};
18 ssl_certificate /etc/letsencrypt/live/{{domain}}/fullchain.pem;
19 ssl_certificate_key /etc/letsencrypt/live/{{domain}}/privkey.pem;
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;
30 ssl_stapling_verify on;
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.
39 gzip_types text/css application/javascript image/svg+xml;
42 # Only connect to this site via HTTPS for the two years
43 add_header Strict-Transport-Security "max-age=63072000";
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";
51 # Upload limit for pictrs
52 client_max_body_size 20M;
60 set $proxpass "http://0.0.0.0:{{ lemmy_ui_port }}";
61 if ($http_accept = "application/activity+json") {
62 set $proxpass "http://0.0.0.0:{{ lemmy_port }}";
64 if ($http_accept = "application/ld+json; profile=\"https://www.w3.org/ns/activitystreams\"") {
65 set $proxpass "http://0.0.0.0:{{ lemmy_port }}";
67 if ($request_method = POST) {
68 set $proxpass "http://0.0.0.0:{{ lemmy_port }}";
72 rewrite ^(.+)/+$ $1 permanent;
74 # Send actual client IP upstream
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;
81 location ~ ^/(api|pictrs|feeds|nodeinfo|.well-known) {
82 proxy_pass http://0.0.0.0:{{ lemmy_port }};
83 proxy_http_version 1.1;
84 proxy_set_header Upgrade $http_upgrade;
85 proxy_set_header Connection "upgrade";
88 limit_req zone=lemmy_ratelimit burst=30 nodelay;
90 # Add IP forwarding headers
91 proxy_set_header X-Real-IP $remote_addr;
92 proxy_set_header Host $host;
93 proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
97 # Redirect pictshare images to pictrs
98 location ~ /pictshare/(.*)$ {
99 return 301 /pictrs/image/$1;
102 location /iframely/ {
103 proxy_pass http://0.0.0.0:8061/;
104 proxy_set_header X-Real-IP $remote_addr;
105 proxy_set_header Host $host;
106 proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
110 # Anonymize IP addresses
111 # https://www.supertechcrew.com/anonymizing-logs-nginx-apache/
112 map $remote_addr $remote_addr_anon {
113 ~(?P<ip>\d+\.\d+\.\d+)\. $ip.0;
114 ~(?P<ip>[^:]+:[^:]+): $ip::;
115 127.0.0.1 $remote_addr;
119 log_format main '$remote_addr_anon - $remote_user [$time_local] "$request" '
120 '$status $body_bytes_sent "$http_referer" "$http_user_agent"';
121 access_log /var/log/nginx/access.log main;