简体   繁体   English

用nginx和节点设置上游?

[英]setting up upstream with nginx and node?

I have three instances on aws. 我有三个实例。 one for nginx which the front-end server, and two backend nodejs intstances. 一个用于前端服务器的nginx,两个用于后端nodejs实例。

Im trying to set up the nginx server to upstream to these node.js instances: 我正在尝试将Nginx服务器设置为这些node.js实例的上游:

upstream node_servers {
        server private_ip:8124 weight=10 max_fails=3; // node server 1 private_ip:port
        server private_ip:8124 weight=10 max_fails=3; // node server 2 private_ip:port
}
server {
    listen  private_ip:80;     // nginx server private ip:port
    root /home/ubuntu/project/;
    server_name public_ip.eu-west-1.compute.amazonaws.com;  // nginx public DNS
    location / {

                try_files $uri $uri/ /index.html;
                proxy_pass http://node_servers/;

     }
}

on my node 1 server, node 2 server instance app.js code: 在我的节点1服务器上,节点2服务器实例app.js代码:

app.listen(8124, "127.0.0.1");
console.log("listening on 8124");

I go to the nginx server public domain name, and nothing really happens, its just loads forever sending request..... 我去Nginx服务器的公共域名,并没有真正发生,它只是加载永远发送请求.....

In your node code, you are listening on the loopback interface on 127.0.0.1 (requests from localhost only): 在您的节点代码中,您正在侦听127.0.0.1上的回送接口(仅来自localhost的请求):

app.listen(8124, "127.0.0.1");

You have to listen on your specific private IP or 0.0.0.0: 您必须侦听您的特定专用IP或0.0.0.0:

app.listen(8124, "0.0.0.0");

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

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