Private
Public Access
The example nginx config set X-Forwarded-For to $proxy_add_x_forwarded_for, which APPENDS to whatever X-Forwarded-For a client already sent rather than replacing it. A client could send its own "X-Forwarded-For: 1.2.3.4" and have it forwarded as the first (trusted) entry — exactly what apps.accounts.views._client_address reads to key the login rate limiter, letting an attacker spoof a different address on every request to dodge the per-address throttle. Changed to $remote_addr, nginx's own view of who actually connected, which overwrites rather than appends. docs/install.md's "different host" proxy guidance also gets a concrete ufw example instead of just "firewall that port" prose, explains why that firewall rule isn't optional (gunicorn trusts whoever can reach it directly as if they were the proxy), and documents an optional Unix socket setup for the same-host case for anyone who wants gunicorn unreachable by anything but the proxy, not just this nginx config. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
65 lines
2.8 KiB
Plaintext
65 lines
2.8 KiB
Plaintext
# Reverse proxy for Evection, for the case where nginx runs on the SAME host
|
|
# as Evection (see docs/install.md's "Reverse proxy" section — if your proxy
|
|
# is on a different host/VM instead, e.g. Nginx Proxy Manager, this file
|
|
# doesn't apply to you directly, but the proxy_set_header lines below still
|
|
# show what any proxy needs to forward). Copy to
|
|
# /etc/nginx/sites-available/evection, adjust server_name, the certificate
|
|
# paths (certbot will fill those in for you if you use `certbot --nginx`),
|
|
# and the port in proxy_pass if you didn't use EVECTION_GUNICORN_BIND's
|
|
# default of 127.0.0.1:8000, then symlink into sites-enabled.
|
|
|
|
server {
|
|
listen 80;
|
|
listen [::]:80;
|
|
server_name your-domain.example;
|
|
|
|
# certbot --nginx adds the HTTPS server block and redirects here
|
|
# automatically; until then this serves plain HTTP.
|
|
location / {
|
|
return 301 https://$host$request_uri;
|
|
}
|
|
}
|
|
|
|
server {
|
|
listen 443 ssl;
|
|
listen [::]:443 ssl;
|
|
server_name your-domain.example;
|
|
|
|
ssl_certificate /etc/letsencrypt/live/your-domain.example/fullchain.pem;
|
|
ssl_certificate_key /etc/letsencrypt/live/your-domain.example/privkey.pem;
|
|
|
|
client_max_body_size 10M; # OPML uploads are small, but leave headroom
|
|
|
|
# Optional: gunicorn already serves /static/ itself via WhiteNoise (with
|
|
# its own far-future cache headers, since filenames are content-hashed),
|
|
# so this block is purely a same-host perf optimization that skips
|
|
# gunicorn for static assets — not required, and not an option at all
|
|
# once the proxy is on a different host than $APP_DIR/staticfiles.
|
|
location /static/ {
|
|
alias /opt/evection/app/staticfiles/;
|
|
expires 30d;
|
|
add_header Cache-Control "public, immutable";
|
|
}
|
|
|
|
# The service worker must be served from the domain root with the right
|
|
# scope header for its Service-Worker-Allowed: / to take effect — it's
|
|
# already a normal Django view (see apps.pwa), proxied like everything
|
|
# else below, so no special-casing is needed here.
|
|
|
|
location / {
|
|
proxy_pass http://127.0.0.1:8000;
|
|
proxy_set_header Host $host;
|
|
proxy_set_header X-Real-IP $remote_addr;
|
|
# $remote_addr, not $proxy_add_x_forwarded_for (S8): the latter
|
|
# APPENDS to whatever X-Forwarded-For a client already sent, so a
|
|
# client could set their own "X-Forwarded-For: 1.2.3.4" and have it
|
|
# forwarded as the first (trusted) hop — Evection's login rate
|
|
# limiter (apps.accounts.views._client_address) and anything else
|
|
# that reads this header take the first entry as the real client
|
|
# address. Overwriting it with nginx's own view of the connecting
|
|
# IP is what actually makes that trust meaningful.
|
|
proxy_set_header X-Forwarded-For $remote_addr;
|
|
proxy_set_header X-Forwarded-Proto $scheme;
|
|
}
|
|
}
|