【日常笔记】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
          
相关推荐
星辰大海14121 小时前
摄影入门学习笔记
笔记·数码相机·学习
嵌入式小羊子1 小时前
TCP/IP是什么?OSI又是什么?
网络·tcp/ip
朝新_1 小时前
【SpringBoot】配置文件
java·spring boot·笔记·后端·spring·javaee
Jul1en_2 小时前
【Excalidraw】简洁好看的超轻量级画图白板
笔记·其他
岑梓铭3 小时前
《考研408数据结构》第七章(6.1~6.3图的概念、存储方式、深/广度遍历)复习笔记
数据结构·笔记·考研·算法·图论·408·ds
biubiubiu07064 小时前
Ubuntu学习笔记
笔记·学习·ubuntu
凉、介4 小时前
ARM 总线技术 —— APB
arm开发·笔记·学习
爱奥尼欧4 小时前
【Linux笔记】网络部分——网络层IP协议
linux·网络·笔记
卷卷的小趴菜学编程5 小时前
Linux系统之----UDP、TCP详解
网络·tcp/ip·udp·滑动窗口·流量控制·拥塞避免·超时重传快重传