0

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.

2

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

2
  • Thank you so much! That worked. Do you have an idea why the previous method does not work? Reading the proxy_pass documentation I really got the impression that proxy_pass would only take the "remaining bits" of the url which is not in the location url and append those to the proxy pass url. So why does your method work and why does mine fail like this? And thanks for the suggestion with the port forwarding! – Felix B. May 3 at 11:41
  • oh - and any comment on the redirect and Host header? – Felix B. May 3 at 11:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.