I have an issue with my Nginx reverse proxy where I have two servers one is front and the other is a back-end API, and I want when I visit the front (https://front.com/urn) it will proxy the request to the back (https://back.com/urn) but at the same time I want my front domain name to be seen in the backend so I’m using this directive
proxy_set_header Host $host;
when I add this directive is when the problem appear, it looks like the response changed to an old response, which I don’t get why is that happening, I’m assuming is cache.
this Nginx config works properly
server_name front.com;
location / {
proxy_pass http://localhost:4500;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
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_cache_bypass $http_upgrade;
}
location /urn {
proxy_pass https://back.com;
}
but when I use this directive “proxy_set_header Host $host;” I always get old response
server_name front.com;
location / {
proxy_pass http://localhost:4500;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
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_cache_bypass $http_upgrade;
}
location /urn {
proxy_pass https://back.com;
proxy_set_header Host $host;
}
this is the api function that is called with https://back.com/urn/$param
public function testDownload(Request $request, $param)
{
dump($param);
dd($request);
}
I tried disabling the cache but I feel like I don’t understand where the problem comes from, and I don’t know where to look for the source of the problem.
proxy_cache_bypass: 1
Please if you can tell me why this is happening and probably how can i fix it, thank you so much.