Private
Public Access
Make the reverse proxy a required, pluggable part of every deployment
gunicorn previously only ever bound to a Unix socket, which assumes the reverse proxy is nginx running on this same host — it can't be reached by a proxy on a different machine at all (e.g. Nginx Proxy Manager on its own box), which is this project's actual deployment target. Switch gunicorn to listening on a plain TCP address instead, controlled by a new EVECTION_GUNICORN_BIND setting in .env. install.sh now asks whether the proxy is local or remote and picks a sensible bind default either way (127.0.0.1:8000 vs 0.0.0.0:8000, with a reminder to firewall the port in the remote case), and no longer tries to automate nginx/certbot itself — docs/install.md's new "Reverse proxy" section covers both shapes instead, since which proxy and where it runs is the operator's choice, not something this script should assume or set up. upgrade.sh's health check now curls the TCP bind instead of the old socket path. Also add WhiteNoise so gunicorn serves /static/ itself: the old approach (nginx aliasing the staticfiles directory on disk) silently breaks the moment the proxy isn't on this host and can't see this filesystem. nginx.conf.example's own /static/ alias becomes an optional same-host perf optimization rather than a requirement. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
1 parent
62702e13e3
commit
21c33e8188
7 files changed
+157
-91
No files matched your search
+21
-3
@@ -3,12 +3,30 @@ from .base import env
|
||||
|
||||
DEBUG = False
|
||||
|
||||
# nginx terminates TLS and proxies to gunicorn over a Unix socket (see
|
||||
# docs/install.md) — this tells Django's request.is_secure() to trust the
|
||||
# header nginx sets, and the redirect/cookie/HSTS settings below assume it.
|
||||
# A reverse proxy (nginx, Caddy, Traefik, Nginx Proxy Manager on another
|
||||
# host, ...) is required in front of gunicorn in every deployment — see
|
||||
# docs/install.md — and it's always the one terminating TLS. This tells
|
||||
# Django's request.is_secure() to trust the X-Forwarded-Proto header it
|
||||
# sets, and the redirect/cookie/HSTS settings below assume it's set.
|
||||
SECURE_SSL_REDIRECT = env.bool("SECURE_SSL_REDIRECT", default=True)
|
||||
SECURE_PROXY_SSL_HEADER = ("HTTP_X_FORWARDED_PROTO", "https")
|
||||
|
||||
# WhiteNoise serves /static/ directly from gunicorn instead of relying on
|
||||
# the reverse proxy to alias the staticfiles directory on disk — the proxy
|
||||
# may not even be on this host (see docs/install.md), so it can't be
|
||||
# trusted to have filesystem access to $APP_DIR/staticfiles.
|
||||
MIDDLEWARE = [
|
||||
"django.middleware.security.SecurityMiddleware",
|
||||
"whitenoise.middleware.WhiteNoiseMiddleware",
|
||||
*MIDDLEWARE[1:], # noqa: F405
|
||||
]
|
||||
STORAGES = {
|
||||
"default": {"BACKEND": "django.core.files.storage.FileSystemStorage"},
|
||||
"staticfiles": {
|
||||
"BACKEND": "whitenoise.storage.CompressedManifestStaticFilesStorage",
|
||||
},
|
||||
}
|
||||
|
||||
SESSION_COOKIE_SECURE = True
|
||||
CSRF_COOKIE_SECURE = True
|
||||
SESSION_COOKIE_SAMESITE = "Lax"
|
||||
|
||||
Reference in new issue
Block a user