Nginx reverse proxy for already deployed mobile api url

Viewed 123

We have an embedded URL in our mobile project like https://www.example.com/api/v1. We can not change this address. We are moving our project to different subdomain so that in nginx we are trying to reverse proxy for reaching out this address.

New address will be https://api.example.com/api/v1 and when mobile project come to https://www.example.com/api/v1 nginx will reverse proxy to > https://api.example.com/api/v1

any body have an idea? Thanks a lot.

location ~/api(.*)$ {
 proxy_set_header X-Real-IP  $remote_addr;
 proxy_set_header X-Forwarded-For $remote_addr;
 proxy_set_header Host $host;
 proxy_pass https://api.example.com/api/$1;
}
1 Answers

This method worked for me.

location ~ ^/somepath/?(.*) {
  resolver 192.xxx.xxx.xxx;
  proxy_pass https://api.example.com/$uri$is_args$args;
}
Related