Nginx proxy_pass在我配置错误页面时停止工作

时间:2020-10-10 21:45:38

标签: nginx nginx-reverse-proxy nginx-config

当服务器在 off 之后位于代理之后的服务器时,我试图创建500错误页面,而对于未找到的静态页面,则试图创建404错误页面。
我已经为proxy_pass工作了localhost:8080messenger,但是在添加自定义错误页面时,我不得不弄乱某些东西,并且它停止了工作。错误页面运行正常,但是mydomain.d/messenger/返回404 19(我从日志中知道),但不返回自定义页面。

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;
        }
        ...

在制作错误页面时,我仅更改了此配置。
curl localhost:8080/messenger/xxx给出预期的输出。
https://mydomain.d/messenger/xxx将我重定向到:
https://mydomain.d/xxx页和404 error页。

因此,总而言之:在为静态文件访问配置错误页面时以及在代理服务器关闭的情况下,我无意间中断了proxy_pass/messenger/的访问,该访问现在仅返回404 19错误。

解决办法是什么?

1 个答案:

答案 0 :(得分:0)

我找到了问题的答案:
/地址的末尾有一个不必要的proxy_pass
错误:

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

右:

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