【日常笔记】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
          
相关推荐
袁小皮皮不皮29 分钟前
1.HCIP BFD 学习笔记(优化版)
服务器·网络·笔记·网络协议·学习·智能路由器·ip
ElevenS_it1885 小时前
Nginx日志监控告警实战:access_log解析+5xx突增+慢请求+异常IP自动告警完整方案(Filebeat+Zabbix)
运维·网络·tcp/ip·nginx·zabbix
hhcgchpspk5 小时前
汇编语言传递数据和地址的误区
汇编·笔记·nasm·masm
智者知已应修善业5 小时前
【51单片机2个外部中断显示中断历时,初始化8左移3位共阳数码管】2024-6-6
c++·经验分享·笔记·算法·51单片机
tq10867 小时前
OperationSequence DSL 2.1 语法规范
笔记
大草原的小灰灰7 小时前
TCP/IP协议栈传输层介绍
网络协议·tcp/ip
智者知已应修善业8 小时前
【用74LS151的实现(16序列信号发生器)】2024-6-1
驱动开发·经验分享·笔记·硬件架构·硬件工程
是上好佳佳佳呀9 小时前
【LangChain|Day04】RAG 全流程基础笔记:Document 、 Loader 和 Splitter
笔记·langchain·rag
俊男无期9 小时前
【无标题】
笔记·其他
m0_719084119 小时前
es我的笔记
大数据·笔记·elasticsearch