DOCKER 部署NGINX容器,配置域名,配置负载均衡

拉镜像
docker pull nginx
新建映射目录
/root/nginx/config/
/root/nginx/logs/
config目录下新增 default.conf文件

client_max_body_size 20m; server { listen 80; server_name 你的域名; access_log off; } server { listen 443 ssl; server_name 你的域名; ssl_certificate 你的域名pem文件路径(这是取得容器路径); ssl_certificate_key 你的域名key文件路径(这是取得容器路径); ssl_session_timeout 5m; ssl_ciphers ECDHE-RSA-AES128-GCM- SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4; ssl_protocols TLSv1 TLSv1.1 TLSv1.2; ssl_prefer_server_ciphers on; location / { proxy_http_version 1.1; proxy_read_timeout 3600s; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection "upgrade"; 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-Proto $scheme; proxy_pass http://ip:port; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection "upgrade"; } access_log off; } 

创建容器网桥
docker network create –subnet=172.28.0.0/16 staticnet
启动NG服务
docker run -d -p 80:80 -p 443:443 -v /root/nginx/config/:/etc/nginx/conf.d/ -v /root/nginx/logs/:/var/log/nginx/ –net staticnet –ip 172.28.0.100 nginx:alpine
启动完成后 需要将部署的域名解析到这台服务器的外网IP

负载均衡配置

client_max_body_size 20m; server { listen 80; server_name 你的域名; access_log off; } upstream lbservers{ server 172.28.0.101:8080; server 172.28.0.102:8080; } server { listen 443 ssl; server_name 你的域名; ssl_certificate 你的域名pem文件路径(这是取得容器路径); ssl_certificate_key 你的域名key文件路径(这是取得容器路径); ssl_session_timeout 5m; ssl_ciphers ECDHE-RSA-AES128-GCM- SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4; ssl_protocols TLSv1 TLSv1.1 TLSv1.2; ssl_prefer_server_ciphers on; location / { proxy_http_version 1.1; proxy_read_timeout 3600s; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection "upgrade"; 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-Proto $scheme; proxy_pass http://lbservers; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection "upgrade"; } access_log off; } 
**修改了配置文件 需要重启nginx容器 ,或者进入容器 reload** 

原文链接:https://blog.csdn.net/weixin_45493805/article/details/129957715

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