Score:0

Unexpected redirect if upstream server redirect in nginx proxy_pass with URI specified

cn flag

This is my reverse proxy server block

server {
    listen 80;
    server_name test.com;

    location / {
        proxy_pass http://127.0.0.1:8080;
        proxy_set_header HOST $host;
    }
}

I creates all endpoint in my upstream server without trailing slash, redirecting all trailing slash endpoint to it's non trailing slash endpoint in my upstream server as well, test.com/foo/ will redirect to test.com/foo, everything is fine until I want proxy test.com to http://127.0.0.1:8080/app/, here's the server block

server {
    listen 80;
    server_name test.com;

    location / {
        proxy_pass http://127.0.0.1:8080/app/;
        proxy_set_header HOST $host;
    }
}

And this is what happened:

  1. test.com redirect to test.com/app, expect test.com
  2. test.com/foo still the same as expected
  3. test.com/foo/ redirect to test.com/app/foo, expect test.com/foo

Can't find the solution to this, any help?

Michael Hampton avatar
cz flag
Make your application aware that you have altered the URL path.
billyzaelani avatar
cn flag
Can the solution is in the server block? not in the application
Michael Hampton avatar
cz flag
You will have to fix the application.
Richard Smith avatar
jp flag
Use `curl -I http://test.com/foo/` to identify the exact value of the `Location` response header, and use `proxy_redirect` to change it.
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.