0

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.

2
  • Simple solution: use another domain (subdomain). Another solution: taught you application that it runs in subdirectory so it should generate links relative to this subdirectory.
    – Alexey Ten
    Mar 11, 2020 at 18:19
  • Yeah we considered both of those and seeing if we can modify either the frontend to adapt to a directory depending on the environment. (the frontend is next.js btw), or requesting the owner of the domain to give us a separate CName dedicated just for this specific server. Both of these have their own obstacles, so I was wondering if there was a solution that I could do purely on the backend/server configuration side only before resorting to modifying the other parts Mar 12, 2020 at 4:41

0

You must log in to answer this question.

Browse other questions tagged .