I can't figure out how to word the question properly, but I'm pretty sure someone has encountered this problem already and I just can't figure out what keywords I should be looking for.
So here's the breakdown. I have this location block in my https.conf:
location ^~ /dev {
allow all;
proxy_set_header X-Forwarded-Host $host;
proxy_set_header X-Forwarded-Server $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_http_version 1.1;
proxy_set_header Connection "";
rewrite ^/dev/(.*) /$1 break;
proxy_pass https://server.name:port/;
}
server.name
is a web application running with node.js.
We can't use location /
as another upstream is already using the root location unrelated to server.name
.
So we can access https://ourdomain.com/dev
and it loads index.js
from server.name
fine. But the problem comes with the file locations. For example, there's a link in index.js
like https://server.name/imagegallery
. Accessing in local of server.name
, the link works fine. But when loading the page through nginx, the link is just https://ourdomain.com/imagegallery
which resolves into a 404. Scripts that the main page needs are also 404'ing so the layout is out of wack.
We tried the following solutions but they're too 'dirty' and just present new limitations:
Attempt 1
Use 'assetPrefix' in the nodejs' next.config.js to soft-include 'dev' at the start of endpoints. It worked fine at first, until we refreshed the page while in https://ourdomain.com/imagegallery
and found out it's suddenly 404'ing again.
Attempt 2
Somehow put all the source files under a 'dev' directory. But the file structure we're dealing with will make this impractical, and we need a new location later for a prod environment which would then be location /prod
in NGINX, making the files weird out again even if we did go through with this.
We're not sure of the best solution to this one, and whether it can be changed purely on one side or both nginx + nodejs frontend have to be changed.
If anyone has any idea, do please let us know. Searching for a solution for this problem is really difficult without the correct keywords.
Thank you.