简体   繁体   English

Nginx将代理传递给另一个Node.js服务器

[英]Nginx pass proxy to another nodejs server

Node js part: 节点js部分:

app.listen(4000,"localhost");

Nginx default: Nginx默认值:

  server{
    server_name "mydomain";
    location /{
    proxy_pass http://localhost:4000;
    }
    }

When i set it with localhost it's working. 当我用本地主机设置它正在工作。

When i run the node script on another server and set nginx configuration like this: 当我在另一台服务器上运行节点脚本并像这样设置nginx配置时:

server{
    server_name "mydomain";
    location /{
    proxy_pass http://192.168.1.30:4000;
    }
    }

This is not working. 这是行不通的。 I'm getting 502 Bad Gateway error when i try to connect "mydomain". 当我尝试连接“ mydomain”时,出现502 Bad Gateway错误。

I've solved the problem with changing the node script. 我已经解决了更改节点脚本的问题。

app.listen(4000,"localhost"); to app.listen(4000); app.listen(4000);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM