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?