nginx reverse proxy : how to troubleshoot 302 redirect loop

Viewed 78

I have configured my nginx to serve a docker container on /wagtail endpoint. When I hit localhost/wagtail it gives me 21 requests with 302 status_code.

I dont understand why it is now doing that as it was working fine until I created 3 docker containers and isolated nginx in one instead of 2 containers with a multi stage build for nginx. I ve tried to put back the configuration which was working and it is not anymore!

When I try to access the /wagtail endpoint it is doing 21 requests in one second and I only have 302 status code and no output in the browser.

What I am missing here?

My nginx.conf is as follow :

server {
    listen 80;
    server_name localhost; 
    location / {
        proxy_pass http://172.20.128.3:3000;
        proxy_set_header Host $host;
        proxy_redirect off;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        client_max_body_size 20M;
        add_header X-Frame-Options "SAMEORIGIN";
    }

    location /wagtail {
        proxy_pass http://172.20.128.2:8000;
        proxy_set_header Host $host;
        proxy_set_header X-Forwarded-Host $host;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Script-Name /wagtail;
        client_max_body_size 20M;
        }

    location /static/ {
        alias /app/static/;
        }       

    location /media/ {
        alias /app/media/;
    }
}

I ve changed the gunicorn --bind 0.0.0.0:8000 to 127.0.0.1:8000 and I now have a bad gateway error... Thank you best ,

0 Answers
Related