【日常笔记】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
          
相关推荐
若云止水1 小时前
Ubuntu 下 nginx-1.24.0 源码分析 - ngx_init_cycle 函数 - 详解(4)
数据库·nginx·ubuntu
Dontla1 小时前
Docker run --add-host参数解析(在容器启动时向/etc/hosts文件中添加自定义的主机名与IP映射)(适用于临时调试或测试)
tcp/ip·docker·容器
浪九天4 小时前
Nginx系列05(负载均衡、动静分离)
nginx·运维开发·持续部署
hgdlip9 小时前
如果更换ip地址会怎么样?网络ip地址怎么更换
网络·网络协议·tcp/ip
cwtlw9 小时前
PhotoShop学习01
笔记·学习·ui·photoshop
远离UE49 小时前
UE5 Computer Shader学习笔记
笔记·学习·ue5
Mr_wilson_liu11 小时前
ssh被暴力访问了,怎么拦截ip
网络·tcp/ip·ssh
m0_7482365811 小时前
Nginx中$http_host、$host、$proxy_host的区别
运维·nginx·http
cmc102811 小时前
47.matlab 中filter design工具设计的滤波器如何在.m代码中调用
笔记
SHIZHK11 小时前
ArcGis若干问题
笔记