Infinite redirect with Nginx https as reverse proxy and docker container
Dear friends, hello!
I have setup a server running Ubuntu Server 18.04 and running Mayan on official Docker container on port 8000.
I have then setup Nginx with https as reverse proxy to listen on port 80 and redirect to 8000.
Here is my Nginx configuration:
` upstream mayan-bahema { server 127.0.0.1:8000; }
server { server_name ged-bahema.educalegal.com.br; client_max_body_size 4G;
access_log /var/log/mayan/bahema-nginx-access.log;
error_log /var/log/mayan/bahema-nginx-error.log;
location /static/ {
proxy_pass http://mayan-bahema;
}
location / {
include proxy_params;
proxy_redirect off;
proxy_pass http://mayan-bahema;
}
listen 443 ssl; # managed by Certbot
ssl_certificate /etc/letsencrypt/live/ged-bahema.educalegal.com.br/fullchain.pem; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/ged-bahema.educalegal.com.br/privkey.pem; # managed by Certbot
include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot
}
server {
if ($host = ged-bahema.educalegal.com.br) {
return 301 https://host
request_uri;
} # managed by Certbot
listen 80;
server_name ged-bahema.educalegal.com.br;
return 404; # managed by Certbot
} `
The server works just fine. But whenever I am not logged in and make requests to:
https://ged-bahema.educalegal.com.br/#/home/
The server responds with infinite redirects util I get a Bad Gateway:
177.8.173.152 - - [10/Jan/2020:16:59:01 +0000] "GET / HTTP/1.1" 302 0 "-" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.88 Safari/537.36" 177.8.173.152 - - [10/Jan/2020:16:59:01 +0000] "GET /authentication/login/?next=/ HTTP/1.1" 200 1321 "-" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.88 Safari/537.36" 177.8.173.152 - - [10/Jan/2020:16:59:01 +0000] "GET /home/?next=/ HTTP/1.1" 302 0 "https://ged-bahema.educalegal.com.br/authentication/login/?next=/" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.88 Safari/537.36" 177.8.173.152 - - [10/Jan/2020:16:59:02 +0000] "GET /authentication/login/?next=/home/%3Fnext%3D/ HTTP/1.1" 200 1326 "https://ged-bahema.educalegal.com.br/authentication/login/?next=/" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.88 Safari/537.36" 177.8.173.152 - - [10/Jan/2020:16:59:02 +0000] "GET /home/?next=/home/%3Fnext%3D/ HTTP/1.1" 302 0 "https://ged-bahema.educalegal.com.br/authentication/login/?next=/home/%3Fnext%3D/" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.88 Safari/537.36" 177.8.173.152 - - [10/Jan/2020:16:59:02 +0000] "GET /authentication/login/?next=/home/%3Fnext%3D/home/%253Fnext%253D/ HTTP/1.1" 200 1340 "https://ged-bahema.educalegal.com.br/authentication/login/?next=/home/%3Fnext%3D/" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.88 Safari/537.36" 177.8.173.152 - - [10/Jan/2020:16:59:02 +0000] "GET /authentication/login/?next=/home/%3Fnext%3D/home/%253Fnext%253D/home/%25253Fnext%25253D/ HTTP/1.1" 200 1347 "https://ged-bahema.educalegal.com.br/authentication/login/?next=/home/%3Fnext%3D/home/%253Fnext%253D/" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.88 Safari/537.36" 177.8.173.152 - - [10/Jan/2020:16:59:02 +0000] "GET /home/?next=/home/%3Fnext%3D/home/%253Fnext%253D/home/%25253Fnext%25253D/ HTTP/1.1" 302 0 "https://ged-bahema.educalegal.com.br/authentication/login/?next=/home/%3Fnext%3D/home/%253Fnext%253D/home/%25253Fnext%25253D/" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.88 Safari/537.36" 177.8.173.152 - - [10/Jan/2020:16:59:03 +0000] "GET /authentication/login/?next=/home/%3Fnext%3D/home/%253Fnext%253D/home/%25253Fnext%25253D/home/%2525253Fnext%2525253D/ HTTP/1.1" 200 1345 "https://ged-bahema.educalegal.com.br/authentication/login/?next=/home/%3Fnext%3D/home/%253Fnext%253D/home/%25253Fnext%25253D/" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.88 Safari/537.36"
I think it is a Nginx issue, because when I access the instance directly using Lynx in the container host directly to port 8000, It correctly redirects to login screen.
Please help! I have tried many different configurations for Nginx, and probably I am doing something stupid.