[英]Nodejs app under nginx and same domain
I'm trying to serve two nodejs apps under the same domain, I configure nginx like this 我试图在同一个域下提供两个nodejs应用,我像这样配置nginx
server {
listen 80;
location /client {
proxy_pass http://127.0.0.1:3000;
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
location / {
proxy_pass http://127.0.0.1:3001;
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}
I can connect to the second app, the one on port 3001, but i cant connect to the one on port 3000 (App1), I get 502 Bad Gateway. 我可以连接到第二个应用程序,端口3001上的一个,但是我无法连接到端口3000(App1)上的一个,我得到502 Bad Gateway。
App1 is running on express 4.x, is there something else i have to configure? App1在Express 4.x上运行,我还需要配置其他内容吗?
server {
listen 80;
root /var/www;
server_name your-domain.com;
location /app1 {
proxy_pass http://localhost:{YOUR_PORT};
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 /app2 {
proxy_pass http://localhost:{YOUR_PORT};
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;
}
}
Try the config similar to above 试试上面类似的配置
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.