好物优选点击查看详情 京东购买

暂无内容

linux nignx 反向代理配置案例:宿主机nginx请求转入docker容器内的宝塔面板nginx,由宝塔面板配置管理网站解析

情景说明

linux 宿主机安装了nginx站点管理、安装了docker容器centos,容器内部搭建了宝塔面板环境(搭建过程)。希望通过宿主机nginx做反向代理,通过端口访问docker内部宝塔面板站点

通过链接http://aaa.com 访问宝塔面板aaa.com站点
宿主机nginx aaa.com.conf配置:

 listen 80; listen [::]:80; server_name aaa.com; location / { proxy_set_header Host $host proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-Host $server_name; proxy_pass http://localhost:7080;  } 

docker容器内宝塔nginx配置 aaa.com.conf:

 listen 80; server_name aaa.com; #站点域名需要跟宿主机的nginx站点一致 root /www/wwwroot/aaa.com; ... location / { ... } ... 

现希望通过外网地址https:www.xxx.com/bt-aaa-bbb/, 访问宝塔面板的aaa.bbb站点
(不推荐,暂无法解决静态资源404问题)

宿主机nginx配置:
打开主网站nginx配置文件,如vi /usr/local/nginx/conf/vhost/www.xxx.com.conf :

 # bt通用站点访问代理配置 location ~ ^/bt-([a-z]+)-([a-z]+)/(.*) { proxy_set_header Host $1.$2; #此处对应宝塔内站点配置的server_name proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-Host $1.$2; #此处对应宝塔内站点配置的server_name proxy_pass http://localhost:7080/$3; #此处对应宝塔内的80端口,docker容器做了端口映射,因此填写映射的宿主机端口 } 

docker容器内宝塔nginx配置:
直接通过宝塔面板,打开对应的aaa.bbb站点配置文件配置即可。或者使用默认配置

尝试访问
https:www.xxx.com/bt-aaa-bbb/ (必须加/结尾)

原文链接:https://blog.csdn.net/u014438244/article/details/120582184

© 版权声明
THE END
喜欢就支持一下吧
点赞0 分享