Nginx proxy_pass stoped working when I was configuring error pages

1.1k Views Asked by At

I was trying to make a 500 error page for a situation when server behind proxy when is off and a 404 error page for not found static pages.
I already had working proxy_pass to localhost:8080 for messenger but while working on adding custom error pages I had to mess something up and it stopped working. Error pages are working all well but mydomain.d/messenger/ returns 404 19 (I know it from logs) but doesn't return the custom page.

erver {
        server_name     mydomain.d;


        # newly added
        location / {
                proxy_pass "http://localhost:8081/";
        }


        # newly added
        location /webapp/planner/ {
                proxy_pass "http://localhost:8082/";
        }

        # was working for some time
        location /messenger/ {
                proxy_pass "http://localhost:8080/";
        }

        # newly added
        location /static/ {
                alias /home/static/;
        }

        # newly added
        error_page 404 /err404.html;
        location = /err404.html {
                root /home/server/errors/err404;
        }

        # newly added 
        error_page 500 502 503 504 /err500.html;
        location = /err500.html {
                root /home/server/errors/err500;
        }
        ...

I changed only this config while making the error pages.
curl localhost:8080/messenger/xxx gives expected output.
https://mydomain.d/messenger/xxx redirects me to:
https://mydomain.d/xxx with 404 error page.

So in summary: When configuring error pages for static file access and for situations when servers behind proxy is down I accidentally broke proxy_pass access to /messenger/ which now only returns an 404 19 error.

What is the fix?

1

There are 1 best solutions below

0
On BEST ANSWER

I found an answer to my problem:
There was an unnecessary / at the end of proxy_pass address.
Wrong:

        location /messenger/ {
                proxy_pass "http://localhost:8080/";
        }

Right:

        location /messenger/ {
                proxy_pass "http://localhost:8080"; #<-- here the '/' at end is gone
        }