主机nginx配置

upstream sx8504{
    #ip_hash; 
    server 172.17.214.108:8504 weight=1;
}
server {
    listen              80;
    server_name         sx.xxxx.com;
    charset  utf-8;    
    location / {  
        proxy_pass  http://sx8504;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For  $proxy_add_x_forwarded_for;
    }
}

集群nginx

server{
        listen 8504;
        root  /data/www;
        location / {
            index  index.html index.htm;
        }   
        ....
}
#监听一个端口

创建集群网络

docker network create -d overlay xxxxcom

集群 yaml

version: "3.9"'"
services:
  ngx:
    image: nginx:1.21.5-alpine
    deploy:
        replicas: 1
    volumes:      
      - /nas/B1/www/sx.xxxx.com/web:/data/www 
      - /nas/B1/www/sx.xxxx.com/svc/logs:/var/log/nginx
      - /nas/B1/www/sx.xxxx.com/svc/conf.d:/etc/nginx/conf.d
      - /nas/B1/www/sx.xxxx.com/svc/nginx.conf:/etc/nginx/nginx.conf
    ports:
      - 8504:8504
    environment:
      - TZ=Asia/Shanghai
    networks:
      - local-net  
networks:
  local-net:
    name: xxxxcom  #使用外部网络
    external: true

启动集群服务

docker stack deploy --compose-file=/nas/B1/www/sx.xxx.com/svc/deploy.yml sxjs
查看部置情况 
docker service ls

部署完成

浏览器调用测试 sx.xxxx.com