0

I got an Flask app in first container and NGINX on second, both hosted on the same server. On NGINX I want to have a proxy to first container, which have no ports exposed for reason that I want the NGINX to serve the app with HTTPS. My nginx.conf looks like this:

http {
        server {
        server_name hostname.domain;
        listen 443 ssl;
        ssl_certificate /hostname_domain.cer;
        ssl_certificate_key /hostname_domain.key;
        location / {
            proxy_pass http://172.17.0.5:80;  # Flask app container IP
        }
    }
}

The app is working fine, when I go to https://hostname.domain, but when I trigger Flask redirect method, like this:

return redirect(url_for("view.whatever"))

that should redirect me to https://hostname.domain/whatever, I am redirected to http://172.17.0.5/whatever. How to fix it and what is causing this behavior? Thanks for any answers!

plepleple
  • 15
  • 7

1 Answers1

0

Thanks for this thread I have managed to fix my problem by adding below options to nginx.conf:

proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;

and configuring Flask app:

app.config["SERVER_NAME"] = "hostname.domain"
plepleple
  • 15
  • 7