使用nginx配置代理内网地址:
客户端->nginx(外网)->nginx(内网)->tomcat。
配置外网的nginx: 1.获取nginx镜像:
客户端->nginx(外网)->nginx(内网)->tomcat。
配置外网的nginx: 1.获取nginx镜像:
docker pull nginx
2.获取nginx配置文件:
docker run --rm -v $PWD/nginx/conf.d/:/root/ nginx cp /etc/nginx/conf.d/default.conf /root/default.conf
3.修改nginx配置文件:
vim nginx/conf.d/default.conf
修改location /{}:
location / {
#root /usr/share/nginx/html;
#index index.html index.htm;
#防止出现404错误
proxy_set_header Host 代理地址;
#proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
#防止出现426错误
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "Upgrade";
#代理地址
proxy_pass http://代理地址/;
}
4.启动nginx:
docker run -v $PWD/nginx/conf.d/:/etc/nginx/conf.d -p 8080:80 -d nginx