Home > database >  Route different base path to same proxy pass Nginx
Route different base path to same proxy pass Nginx

Time:05-29

I want to pass different path to the same proxy_pass but I keep getting 502 Bad gateway.

These path use the same port number but different base path. How do I make it work from what I have which returns an error currently.

this is what my current location looks like

worker_processes 4;
# worker_process auto
events { worker_connections 1024; }

http {

    server {

        listen 80;
        charset utf-8;

        location ~ ^/api/v1/(wallet|card)/(.*)$ {
            proxy_pass http://wallet-service:3007/api/v1/$1/;
            proxy_http_version 1.1;
            proxy_set_header Upgrade $http_upgrade;
            proxy_set_header Connection 'Upgrade';
            proxy_set_header Host $host;
            proxy_cache_bypass $http_upgrade;
        }
    }
}

CodePudding user response:

If you don't need an URI to be changed at all, don't use anything other than the upstream name:

location ~ ^/api/v1/(wallet|card)/ {
    proxy_pass http://wallet-service:3007;
    ...
}

If an URI needs to be rewritten before being passed to the upstream, check this answer to see how to do it.

  • Related