NGINX - reverse proxy server API on different ports

I have the following API (s):

  • localhost: 300 / api / customers /
  • local: 400 / API / clients /: identifier / billing
  • local: 500 / API / orders

I would like to use NGINX so that they all work in the following place:

local: 443 / API /

This seems very complicated because clients span two servers.

Here is my unsuccessful attempt starting with orders

server {
    listen 443;
    server_name localhost;

    location /api/orders {
            proxy_pass https://localhost:500/api/orders;
            proxy_set_header Host $host;
            proxy_set_header X-Forwarded-For $remote_addr;
    }
}


server {
    listen 443;
    server_name localhost;

    location /api/customers/$id/billing {
            proxy_pass https://localhost:400/api/customers/$id/billing;
            proxy_set_header Host $host;
            proxy_set_header X-Forwarded-For $remote_addr;
    }
}

server {
    listen 443;
    server_name localhost;

    location /api/customers {
            proxy_pass https://localhost:300/api/customers;
            proxy_set_header Host $host;
            proxy_set_header X-Forwarded-For $remote_addr;
    }
}

Does something jump before the fix? Thank!

+12
source share
2 answers

( nginx), location server. .

URI , URI proxy_pass.

server {
{
    listen 443;
    server_name localhost;

    proxy_set_header Host $host;
    proxy_set_header X-Forwarded-For $remote_addr;

    location /api/orders {
        proxy_pass https://localhost:500;
    }
    location /api/customers {
        proxy_pass https://localhost:400;
    }
    location = /api/customers {
        proxy_pass https://localhost:300;
    }
}

proxy_set_header , .

location URI, localhost:300/api/customers/. URI, = . - URI, /api/customers/:id/billing, . .

, , SSL . - .

+16

; , Kubernetes, IP- ( Kubernetes). IP - - 10.ttt.ttt.104 , .

nginx length-, - , ,

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/;
       }
     }
}
0

Source: https://habr.com/ru/post/1656220/


All Articles