Jas*_*nes 7 linux reverse-proxy nginx
上landing.example.com:10000有我一个web服务器工作正常,这是一个码头工人的容器暴露的端口10000。它的 IP 是172.17.0.2.
我想要的是在 port 上有一个 nginx 反向代理80,并根据访问者访问的 URL 将访问者发送到不同的 Docker 容器。
server {
listen 80;
server_name landing.example.com;
location / {
proxy_pass http://172.17.0.2:10000/;
}
access_log /landing-access.log;
error_log /landing-error.log info;
}
Run Code Online (Sandbox Code Playgroud)
当我这样做时,我得到502 Bad Gateway并且日志说
2016/04/14 16:58:16 [error] 413#413: *84 connect()
failed (111: Connection refused) while connecting to upstream, client:
xxx.xxx.xxx.xxx, server: landing.example.com, request: "GET / HTTP/1.1",
upstream: "http://172.17.0.2:10000/", host: "landing.example.com"
Run Code Online (Sandbox Code Playgroud)
尝试这个:
upstream my_server {
server 172.17.0.2:10000;
}
server {
listen 80;
server_name landing.example.com;
location / {
proxy_pass http://my_server;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_http_version 1.1;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto http;
proxy_redirect http:// $scheme://;
}
}
Run Code Online (Sandbox Code Playgroud)
在这里您定义上游服务器(您的服务器通过 IP 或主机名)并确保也转发标头,以便回答的服务器知道要回答的人。
| 归档时间: |
|
| 查看次数: |
13521 次 |
| 最近记录: |