Nginx 容器反向代理宿主机的服务
1
2
3
4
5
6
7
8
9
10
11
12
13
|
server {
listen 80;
server_name www.example.com;
location / {
# 关键! 172.17.0.1 是 Nginx 容器所在 Docker 网络的网关地址
proxy_pass http://172.17.0.1:7190;
# 一些其他的代理设置
proxy_redirect off;
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_proxy, https:proxy 环境变量
1
2
|
export http_proxy='http://172.17.0.2:7890'
export https_proxy='http://172.17.0.2:7890'
|