Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Nginx reverse proxy for already deployed mobile api url

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;
}
like image 243
Serhan Avatar asked Jan 30 '26 15:01

Serhan


1 Answers

This method worked for me.

location ~ ^/somepath/?(.*) {
  resolver 192.xxx.xxx.xxx;
  proxy_pass https://api.example.com/$uri$is_args$args;
}
like image 151
Serhan Avatar answered Feb 03 '26 09:02

Serhan



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!