当位置路径不是/时,Node.js应用程序无法加载 [英] Node.js app doesn't load when location path is not /

查看:99
本文介绍了当位置路径不是/时,Node.js应用程序无法加载的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

由于某种原因,我在127.0.0.1:8081上运行的Node.js应用需要/.

For some reason, my Node.js app running on 127.0.0.1:8081 requires /.

如果从此开始, //projectb都可以加载页面.

If I start with this, BOTH / and /projectb are able to load the page.

server {
        listen 80;

        location / {
                proxy_pass http://127.0.0.1:8081;

                proxy_http_version 1.1;
                proxy_set_header Upgrade $http_upgrade;
                proxy_set_header Connection "upgrade";
        }

        location /projectb {
                proxy_pass http://127.0.0.1:8081/;

                proxy_http_version 1.1;
                proxy_set_header Upgrade $http_upgrade;
                proxy_set_header Connection "upgrade";
        }
}

当我将其更改为/projectb时,它不再能够完全加载页面.当我查看网络"标签时,某些(但不是全部)请求失败,例如某些图像,.js,一些错误的端点.

When I change it to this, /projectb is no longer able to fully load the page. When I look at the network tab, some (but not all) requests fail, for example some images, .js, some wrong endpoints.

server {
        listen 80;

        location /somethingelse {
                proxy_pass http://127.0.0.1:8080/;

                proxy_http_version 1.1;
                proxy_set_header Upgrade $http_upgrade;
                proxy_set_header Connection "upgrade";
        }

        location /projectb {  # I'd expect this to still work.
                proxy_pass http://127.0.0.1:8081/;

                proxy_http_version 1.1;
                proxy_set_header Upgrade $http_upgrade;
                proxy_set_header Connection "upgrade";
        }
}

总而言之,当我直接按下端口123.456.78.910:8081时,当我同时具有//projectb代理到http://127.0.0.1:8081/时,以及当我单独代理到/时,它都起作用,但是当我自己代理/projectb.

To summarize, it works when I hit the port directly 123.456.78.910:8081, and when I have BOTH / and /projectb proxy to http://127.0.0.1:8081/, and when I proxy to / by itself, but not when I proxy to /projectb by itself.

为什么会这样?

推荐答案

如果location /projectb在没有location /的情况下无法工作,则表示location /projectb的配置不正确.您是否尝试过删除location /projectb以查看它是否仅适用于location /?

If location /projectb doesn't work without location / then it means that location /projectb is not configured properly. Have you tried removing location /projectb to see if it works with just location /?

您的nginx应该将请求代理到哪个端点?是http://127.0.0.1:8081/还是http://127.0.0.1:8081/projectb?我觉得它是http://127.0.0.1:8081/projectb.

What endpoint your nginx should proxy requests to? Is it http://127.0.0.1:8081/ or http://127.0.0.1:8081/projectb? I have a feeling that it's http://127.0.0.1:8081/projectb.

请尝试从第二个片段的proxy_pass http://127.0.0.1:8081/;行中删除尾部斜杠.

Please try to remove the trailing slash from proxy_pass http://127.0.0.1:8081/; line in the second snippet.

这篇关于当位置路径不是/时,Node.js应用程序无法加载的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆