我安装了nginx以服务多个nodejs应用程序
在我的服务器上,我有2个应用程序myapp和pm2-web
nginx配置看起来像这样
http {
# .... logs, gzip ... etc
server {
location / {
proxy_pass http://localhost:5000;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
}
location /pm2 {
proxy_pass http://localhost:9000;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
}
}
我的应用运行正常,但是当我尝试访问/pm2
我收到以下错误
Cannot GET /pm2
当pm2-web未运行时,我得到502 Bad Gateway
但我仍然可以从http://IP:9000
答案 0 :(得分:0)
网址的/pm2
部分正在传递到您的Node应用程序,在那里它与任何路径都不匹配。
即,您的pm2应用程序正在9000
上运行,但您正在尝试访问不存在的http://localhost:9000/pm2
。
在代理传递URL中包含一个尾部斜杠,以确保不包含/pm2
:
location /pm2 {
proxy_pass http://localhost:9000/;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
}