起一个docker容器
docker run -dit \
-p 8002:80 \
-v /www/lhsqxxxt/www:/www \
-v /www/lhsqxxxt/extensions:/usr/local/src \
-v /www/lhsqxxxt/conf:/etc/nginx \
--privileged=true \
--name=lhsqxxxt_cmmlnmp \
royeecai/cmmlnmp
这台主机上运行了两个docker容器,分别绑定主机的8001和8002端口
现在我们想通本本机nginx代理功能实现宿主机通过80端口对外提供web服务。
- 配置信息如下
cd /usr/local/nginx/conf/vhosts/
[root@iZm5eejq1i5n8h97elgv2tZ vhosts]# ls
52qcg.cn.conf test.52qcg.conf test.conf
[root@iZm5eejq1i5n8h97elgv2tZ vhosts]# cat test.52qcg.conf
upstream my_server1 {
server 127.0.0.1:8002;
keepalive 2000;
}
server{
##配置80端口自动跳转443
listen 80;
server_name test.52qcg.cn;
#rewrite ^(.*)$ https://$host$1 permanent;
location / {
proxy_pass http://my_server1;
proxy_set_header Host $host:$server_port;
}
}
[root@iZm5eejq1i5n8h97elgv2tZ vhosts]# cat test.conf
upstream my_server {
server 127.0.0.1:8001;
keepalive 2000;
}
server{
##配置80端口自动跳转443
listen 80;
server_name 127.0.0.1;
#rewrite ^(.*)$ https://$host$1 permanent;
location / {
proxy_pass http://my_server;
proxy_set_header Host $host:$server_port;
}
}
- 访问效果