Nginx proxy https to http on non standard port?

15,833

This is more an issue of the application running on the upstream host (Tracks), not of the web server configuration (unless your upstream web server configuration contains rewrite rules, of course). Different applications handle these situations differently: some require an explicit configuration parameter telling them the actual URL the application can be reached at, some use certain HTTP headers, some use other HTTP headers.

As Tracks is a Rails application you might end up getting more knowledgeable answers if you add a corresponding tag to your question.

Share:
15,833
kenen
Author by

kenen

Updated on June 16, 2022

Comments

  • kenen
    kenen about 2 years

    I have nginx configured to proxy https traffic to an http server running on the same machine.

    Everything works fine when I configure nginx to listen on / proxy from https port 443. But I really want to listen on a non standard port. When I configure a non standard port, nginx receives the request and sends it to my http server, as it should, but the server is responding with an HTTP redirect back to the browser that tells it to redirect to 'https://server.com/someurl". I mean the redirect url looks good except for it's missing the correct port. Am I missing an HTTP header that I need to be setting in the proxy?

    Specifically I'm running an http instance of Tracks; http://getontracks.org. If it matters.

    My (working on standard port) nginx server configuration:

    location /{
        proxy_pass http://localhost:50000;
        proxy_next_upstream error timeout invalid_header http_500 http_502 http_503;
        proxy_set_header Host $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 https;
        proxy_redirect off;
    }