欢迎来到尧图网

客户服务 关于我们

您的位置:首页 > 汽车 > 维修 > 【日常笔记】nginx端口转发到其他ip:端口

【日常笔记】nginx端口转发到其他ip:端口

2025/10/13 7:26:05 来源:https://blog.csdn.net/ladymorgana/article/details/144434121  浏览:    关键词:【日常笔记】nginx端口转发到其他ip:端口

项目场景:

微服务迁移至其它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: alwayscontainer_name: nginx-javaimage: nginx:1.17.6ports:- 11111:11111volumes:- ./nginx.conf:/etc/nginx/nginx.conf- ./nginx-log:/var/log/nginx- ./html:/etc/nginx/html- ./cert:/etc/nginx/certdeploy:resources:limits:memory: 500Mreservations:memory: 200M

Step 3:新ECS

确保服务正常http://220.xxx.xxx.xxx:22222

Step 4:原ECS :重新构建nginx

docker-compose up -d --build

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com

热搜词