项目场景:
微服务迁移至其它ECS服务器:
-
原ECS ip:110.xxx.xxx.xxx:11111
-
迁移至新ECS ip:220.xxx.xxx.xxx:22222
-
nginx docker部署
实战
Step 1:原ECS :修改nginx.conf
添加如下代码
server {
listen 11111;
location / {
proxy_pass http://220.xxx.xxx.xxx:22222;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}
Step 2:原ECS :修改 docker-compose.yaml
添加端口:11111:11111
version: '3.1'
services:
nginx:
restart: always
container_name: nginx-java
image: nginx:1.17.6
ports:
- 11111:11111
volumes:
- ./nginx.conf:/etc/nginx/nginx.conf
- ./nginx-log:/var/log/nginx
- ./html:/etc/nginx/html
- ./cert:/etc/nginx/cert
deploy:
resources:
limits:
memory: 500M
reservations:
memory: 200M
Step 3:新ECS
确保服务正常http://220.xxx.xxx.xxx:22222
Step 4:原ECS :重新构建nginx
docker-compose up -d --build