我有两个Amazon EC2实例。我将它们分别命名为X和Y。我在两者上均安装了Nginx。 Y在端口3000
上运行resque。只有X具有公共IP和域example.com。假设Y的私有IP为15.0.0.10
我想要的是所有请求都发送到X。并且仅当请求url与模式/resque
匹配时,才应由Y在localhost:3000/overview
(即resque Web界面)处进行处理。似乎可以使用nginx config中的proxy_pass来完成。
因此,在nginx.conf中,我添加了以下内容:
location /resque {
real_ip_header X-Forwarded-For;
set_real_ip_from 0.0.0.0/0;
allow all;
proxy_pass http://15.0.0.10:3000/overview;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
但是现在,当我从Web浏览器访问
http://example.com/resque
时,它显示为502 Bad Gateway
。在X的
/var/log/nginx/error.log
中,2014/02/27 10:27:16 [error] 12559#0: *2588 connect() failed (111: Connection
refused) while connecting to upstream, client: 123.201.181.82, server: _,
request: "GET /resque HTTP/1.1", upstream: "http://15.0.0.10:3000/overview",
host: "example.com"
关于可能出什么问题以及如何解决此问题的任何建议?
最佳答案
事实证明,如果需要通过寻址实例的IP使其可访问,则服务器应在0.0.0.0上运行。
因此,为了解决我的问题,我停止了在127.0.0.1:3000上运行resque的服务器,并重新启动它以绑定到0.0.0.0:3000。休息一切都与上面相同,并且可以工作。谢谢。
供参考:Curl amazon EC2 instance