1

currently I have this as my proxy_pass which works fine

    location = /sms/resetpass {
             proxy_pass http://xxx.xxx.xxx.xxx/api/resetpass;
             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;
    }

the above works fine but I figured if I want another proxy such as

    location = /sms/sample1 {
             proxy_pass http://xxx.xxx.xxx.xxx/api/sample1;
             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;
    }

then I have to make another location block

is it possible to do something like this?

    location = /sms/something_here {
             proxy_pass http://xxx.xxx.xxx.xxx/api/something_here;
             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;
    }

where something_here means if I pass in any url into sms/blah then the proxy_pass would be api/blah

I tried to google something like proxy_pass with subpath or something like that but doesn't seem to be what I need. So I am wondering if this is possible or I just didn't know the right word to find it?

Thanks in advance for any advices.

Dora
  • 341
  • 1
  • 5
  • 15

1 Answers1

4

Use nginx location and rewrite directives, something like this should be fine:

location ~ ^/sms/ {
    rewrite ^/sms/(.*) /api/$1 break;
    proxy_pass http://1.2.3.4;
    ...
}

don't forget to test it first.

mforsetti
  • 2,666
  • 2
  • 16
  • 20