diff mbox series

[layerindex-web,2/4] docker: set X-Forwarded-Proto in the nginx configs

Message ID 20261018214146.67856-3-tim.orling@konsulko.com
State New
Headers show
Series Docker: environment files for dev, staging and production | expand

Commit Message

Tim Orling Oct. 18, 2026, 9:41 p.m. UTC
docker/settings.py sets SECURE_PROXY_SSL_HEADER to trust
X-Forwarded-Proto, but nginx never sent it, so Django treated every
request as plain HTTP even when served over HTTPS: request.is_secure()
was false and absolute URLs it built used http://. Set it from $scheme,
which also overwrites any value the client sends.

This also fixes the 403 on login when the site is served on a
non-default HTTPS port such as https://localhost:8081: Django now sees
the request as secure, so the browser's Origin matches the request
without listing the port in CSRF_TRUSTED_ORIGINS.

Fixes [YOCTO #15329]

AI-Generated: Claude Opus 5.5
Signed-off-by: Tim Orling <tim.orling@konsulko.com>
---
 docker/nginx-ssl.conf | 2 ++
 docker/nginx.conf     | 1 +
 2 files changed, 3 insertions(+)
diff mbox series

Patch

diff --git a/docker/nginx-ssl.conf b/docker/nginx-ssl.conf
index 9776b8f..75f01ee 100644
--- a/docker/nginx-ssl.conf
+++ b/docker/nginx-ssl.conf
@@ -70,6 +70,7 @@  http {
 
         location @proxy_to_app {
             proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
+            proxy_set_header X-Forwarded-Proto $scheme;
             proxy_set_header Host $http_host;
             proxy_redirect off;
 
@@ -132,6 +133,7 @@  http {
 
         location @proxy_to_app {
             proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
+            proxy_set_header X-Forwarded-Proto $scheme;
             proxy_set_header Host $http_host;
             proxy_redirect off;
 
diff --git a/docker/nginx.conf b/docker/nginx.conf
index eda3474..0a47a1c 100644
--- a/docker/nginx.conf
+++ b/docker/nginx.conf
@@ -37,6 +37,7 @@  http {
 
         location @proxy_to_app {
             proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
+            proxy_set_header X-Forwarded-Proto $scheme;
             proxy_set_header Host $http_host;
             proxy_redirect off;