NGINX - Reverse proxy multiple API on different ports

前端 未结 2 1717
Happy的楠姐
Happy的楠姐 2021-02-01 05:10

I have the following API(s):

  1. localhost:300/api/customers/
  2. localhost:400/api/customers/:id/billing
  3. localhost:500/api/orders

I\'d l

2条回答
  •  孤独总比滥情好
    2021-02-01 06:06

    The accepted answer did not work for me; I had three servers running as Kubernetes service mapped to different Cluster IP's (accessible only from Kubernetes nodes). So I used the host machine IP - 10.ttt.ttt.104 and the following configuration so that I could access these services from my work network.

    I am not an nginx expert by any length- but this worked -- so use it as base maybe

    events {
      worker_connections  4096;  ## Default: 1024
    }
    http{
        server {
           listen 80;
           listen [::]:80;
    
           server_name 10.ttt.ttt.104;
           proxy_set_header Host $host;
           proxy_set_header X-Forwarded-For $remote_addr;
    
           location / {
               proxy_pass http://10.103.152.188:80/;
           }
         }
    
        server {
           listen 9090;
           listen [::]:9090;
    
           server_name 10.ttt.ttt.104;
           proxy_set_header Host $host;
           proxy_set_header X-Forwarded-For $remote_addr;
    
           location / {
               proxy_pass http://10.107.115.44:9091/;
           }
         }
    
        server {
           listen 8080;
           listen [::]:8080;
    
           server_name 10.ttt.ttt.104;
           proxy_set_header Host $host;
           proxy_set_header X-Forwarded-For $remote_addr;
    
           location / {
               proxy_pass http://10.105.249.237:80/;
           }
         }
    }
    

提交回复
热议问题