【发布时间】:2014-03-30 19:14:23
【问题描述】:
我有两个 Amazon EC2 实例。让我称它们为 X 和 Y。我在它们两个上都安装了 nginx。 Y 有 resque 在端口 3000 上运行。只有 X 有一个公共 IP 和域 example.com。假设Y的私网IP是15.0.0.10
我想要的是所有请求都到 X。并且只有当请求 url 匹配模式 /resque 时,它才应该由位于 localhost:3000/overview 的 Y 处理,这是 resque Web 界面。这似乎可以在 nginx 配置中使用 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;
}
但是现在,当我从网络浏览器访问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"
关于可能出现的问题以及如何解决此问题的任何建议?
【问题讨论】:
-
您的 resque 是否在 15.0.0.10:3000 上收听?可能它会监听 localhost:3000。
-
@alexeyten 他们应该是一样的
-
没有。 localhost 是 127.0.0.1,只能从同一台机器访问。
-
http://15.0.0.10:3000/overview自己工作吗?
标签: nginx proxy amazon-ec2 resque