Score:0

Nginx reverse proxy routes subdirectory to root location proxy path on first page visit each browser session

zw flag

Short: I have two different servers behind an nginx proxy. When I try to reach one of them I will always be redirected to the other one which is located at the root location. This happens ONCE. The logs imply that Firefox/Chrome do not send a GET request to nginx when I enter the address the first time. When I enter the URL a second time in a Firefox/Chrome session I will reach the correct server.

Longer: In my setup I have two servers within a docker network where "https://server.app/" should be routed to "http://docker-server-1:80" and "https://server.app/client" should be passed to "http://docker-server-2:8090/client".

My nginx config looks like this

events {}

http {
    server {
        server_name         server.app;
        listen              443 ssl;
        ssl_certificate     /etc/nginx/fullchain.pem;
        ssl_certificate_key /etc/nginx/privkey.pem;
        error_log           /etc/nginx/nginx.log debug;

        location /client {
            proxy_pass http://docker-server-2:8090/client;
            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 $scheme;
        }

        location / {
            proxy_pass http://docker-server-1:80;
            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 $scheme;
        }
    }
}

When I enter "https://server.app/client", I will reach the correct server when a) I open this page in Firefox/Chrome incognito mode, b) I use a simple and naive tool like curl/wget, c) I cleared the cache of Firefox/Chrome and they have never seen "https://server.app" before or d) I append index.html and enter "https://server.app/client/index.html".

When I visit "https://server.app" and try to later open "https://server.app/client", the page "https://server.app" will be loaded instead ONCE per browser session. When I enter the subdirectory URL a second time, I will reach the correct server until I close my browser and open it again. Then I will end ONCE again at "https://server.app" when I enter "https://server.app/client".

The weird part is, I don't see any GET request in the nginx log when entering "https://server.app/client" with non-incognito Firefox/Chrome. It seems like both browsers use a cached version of "https://server.app" when I enter "https://server.app/client" but I cannot figure out why. This is why I assume that the browsers are part of the problem but how can I tell them to not do this redirect?

djdomi avatar
za flag
did you tried curl?
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.