NGINX – Reverse proxy multiple API on different ports

The three services are being proxied by the same server (as far as nginx is concerned) so must be structured as three location blocks within one server block. See this document for details.

If you are just passing the original URI unmodified, you do not need to specify a URI on the proxy_pass statement.

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

If the proxy_set_header statements are identical, they can be specified once in the parent block.

The type of location statement required is dependent on the range of URIs processed by the localhost:300/api/customers/ service. If it is one URI, the = syntax will work. If it is any URI that does not match /api/customers/:id/billing, then you will need to use a regular expression location block. See this document for details.

I am not sure that this will work unless you terminate SSL here. That is configure the reverse proxy as a secure server.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)