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

项目场景:

微服务迁移至其它ECS服务器:

  • 原ECS ip:110.xxx.xxx.xxx:11111

  • 迁移至新ECS ip:220.xxx.xxx.xxx:22222

  • nginx docker部署

实战

Step 1:原ECS :修改nginx.conf

添加如下代码

c 复制代码
	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

c 复制代码
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

c 复制代码
docker-compose up -d --build
          
相关推荐
宵时待雨14 分钟前
STM32笔记归纳6:中断
笔记·stm32·嵌入式硬件
玉梅小洋30 分钟前
Linux命令详解 —— IP 命令及永久配置
linux·运维·tcp/ip
BlackWolfSky38 分钟前
鸿蒙高级课程笔记1—应用DFX能力介绍
笔记·华为·harmonyos
huohaiyu1 小时前
IP协议详解
服务器·网络·tcp/ip
别了,李亚普诺夫1 小时前
数字测速方法和PID控制
笔记·学习·电机
LaoZhangGong1232 小时前
学习TCP/IP的第9步:客户端和服务端综合测试
网络·学习·tcp/ip
1104.北光c°2 小时前
【黑马点评项目笔记 | 登录篇】Redis实现共享Session登录
java·开发语言·数据库·redis·笔记·spring·java-ee
曾浩轩2 小时前
C语言学习记录——BC119 最高分与最低分之差
c语言·笔记·学习
EmbedLinX2 小时前
Linux 之网络通信
linux·服务器·c语言·笔记·学习
claider3 小时前
Vim User Manual 阅读笔记 usr_22.txt Finding the file to edit 多文件编辑浏览
笔记·编辑器·vim