AWS ElasticBeanstalk上的502错误网关Nginx节点

时间:2015-07-07 22:29:43

标签: node.js amazon-web-services nginx amazon-ec2 elastic-beanstalk

我已经阅读了很多关于解决这个问题的帖子,但到目前为止没有任何工作,我没有想法。

我有一个Express Generator应用程序,在本地运行正常,在AWS Elastic Beanstalk网站上运行一次。

EB作为单个实例运行,安全组允许PORT 80 tcp从0.0.0.0/0开始,其余的都是默认EB配置(ip表,nginx conf等)

这就是我要去的地方......

1)将节点命令设置为npm start以确保它运行而不是app.js
2)更新了EC2 env PATH,以便将当前node / npm添加到其中 3)确保节点端口运行为8081
4)检查节点实际运行正常(在盒子上我可以通过IP和弹性beanstalk ULR成功完成CURL)

但是从盒子外面,弹性beanstalk url返回502并出现此错误..

2015/07/07 21:54:59 [error] 7883#0: *4 connect() failed (111: Connection refused) while connecting to upstream, client: 94.174.20.81, server: , request: "GET /favicon.ico HTTP/1.1", upstream: "http://127.0.0.1:8081/favicon.ico", host: "ae-prod.elasticbeanstalk.com", referrer: "http://ae-prod.elasticbeanstalk.com/"

Nginx配置

upstream nodejs {
    server 127.0.0.1:8081;
    keepalive 256;
}

server {
    listen 8080;

    location / {
        proxy_pass  http://nodejs;
        proxy_set_header   Connection "";
        proxy_http_version 1.1;
        proxy_set_header        Host            $host;
        proxy_set_header        X-Real-IP       $remote_addr;
        proxy_set_header        X-Forwarded-For $proxy_add_x_forwarded_for;
    }


}

包装盒上的IP表格如下所示..

$sudo iptables -t nat -L

Chain PREROUTING (policy ACCEPT)
target     prot opt source               destination
REDIRECT   tcp  --  anywhere             anywhere             tcp dpt:http redir ports 8080

Chain INPUT (policy ACCEPT)
target     prot opt source               destination

Chain OUTPUT (policy ACCEPT)
target     prot opt source               destination
REDIRECT   tcp  --  anywhere             anywhere             tcp dpt:http redir ports 8080

Chain POSTROUTING (policy ACCEPT)
target     prot opt source               destination

有人有任何想法吗?

1 个答案:

答案 0 :(得分:1)

我遇到了同样的问题,结果发现我的节点应用程序由于缺少依赖项而无法启动。检查主机上是否运行了nodejs或npm进程。如果没有去

/var/app/current

并尝试通过npm start手动启动您的应用。如果它在启动时抛出错误或启动失败,则可能是502的原因。