lemmy/nginx.conf.tmpl

82 lines
2.2 KiB
Cheetah

limit_req_zone $binary_remote_addr zone=lemmy_ratelimit:10m rate=1r/s;
upstream backend {
server "{{ env "STACK_NAME" }}_app:8536";
}
upstream frontend {
server "{{ env "STACK_NAME" }}_ui:1234";
}
server {
listen 80;
listen [::]:80;
server_name {{ env "DOMAIN" }};
# Hide nginx version
server_tokens off;
# Enable compression for JS/CSS/HTML bundle, for improved client load times.
# It might be nice to compress JSON, but leaving that out to protect against potential
# compression+encryption information leak attacks like BREACH.
gzip on;
gzip_types text/css application/javascript image/svg+xml;
gzip_vary on;
# Upload limit for pictrs
client_max_body_size 20M;
# frontend
location / {
set $proxpass "http://frontend";
if ($http_accept ~ "^application/.*$") {
set $proxpass "http://backend";
}
if ($request_method = POST) {
set $proxpass "http://backend";
}
proxy_pass $proxpass;
rewrite ^(.+)/+$ $1 permanent;
# Send actual client IP upstream
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
# backend
location ~ ^/(api|pictrs|feeds|nodeinfo|.well-known) {
proxy_pass "http://{{ env "STACK_NAME" }}_app:8536";
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
# Rate limit
limit_req zone=lemmy_ratelimit burst=30 nodelay;
# Add IP forwarding headers
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
# Redirect pictshare images to pictrs
location ~ /pictshare/(.*)$ {
return 301 /pictrs/image/$1;
}
}
# Anonymize IP addresses
# https://www.supertechcrew.com/anonymizing-logs-nginx-apache/
map $remote_addr $remote_addr_anon {
~(?P<ip>\d+\.\d+\.\d+)\. $ip.0;
~(?P<ip>[^:]+:[^:]+): $ip::;
127.0.0.1 $remote_addr;
::1 $remote_addr;
default 0.0.0.0;
}
access_log /var/log/nginx/access.log combined;