NGINX proxy_pass serving index instead of requested java-script file with status 200

I have set up a proxy_pass looking like this:

location /review/app-template/16-update-to-proxy_pass/ {
        proxy_pass http://$server_name:54341/review/app-template/16-update-to-proxy_pass/;

        # proxy_set_header Host $host;
        # proxy_redirect http://$server_name:54341/review/app-template/16-update-to-proxy_pass/ /review/app-template/16-update-to-proxy_pass/;

        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; 
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-Proto $scheme;
}

The commented out code was an attempt to debug - but the commenting out had no noticable effect on this (I used nginx -s reload)

The dash app found under the port 54341 works fine:

enter image description here

But if I open the app through nginx it is broken:

enter image description here

What is broken?

So it appears that something is wrong with java script files so here is a side by side of these java script files. The broken version seems to return the index file:

renders index

while the working version actually returns a java script file:

java script source

How to Approach this Problem?

I am unsure how to even debug this. Curl does the same and the status codes are 200 as if nothing was wrong. Nginx seems to be happy to serve the wrong file (the index html) under the same name as the requested file. So no error logs... I am utterly and completely stuck.

If there is any more information that would be helpful I am happy to add more. But for now this seems like the things needed.


As you're passing all requests through to your dash app backend without modification, try proxy_pass without a URI.

For example, try the following:

location /review/app-template/16-update-to-proxy_pass/ {
        proxy_pass http://$server_name:54341;

        # proxy_set_header Host $host;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; 
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-Proto $scheme;
        proxy_set_header X-Forwarded-Port $server_port;
}

It's great to see you passing through X-Forwarded-For, X-Real-IP, X-Forwarded-Proto.

In many cases, I also recommend passing through the X-Forwarded-Port header too, so your app knows what frontend port your visitor is actually connecting to.

Kind regards David