Home > Mobile >  How to remove some part of path in nginx reverse proxy
How to remove some part of path in nginx reverse proxy

Time:03-24

I've set frontend api url endpoint to something like this https://host/api/login which is host means nginx reverse proxy

Inside nginx config I've done something like this

location ~* ^/api/ {
    proxy_set_header Host $host;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_pass http://somehost/$1$is_args$args;
}

I don't sure if it's correct but above code I want it to catch request that has /api at the first path and send request to proxy_pass's url along with the same path. But I don't want to use /api for this.

For example if frontend has request to /api/login path. I want to send request to http://somehost/login. So how can I remove /api inside nginx.conf file ?

CodePudding user response:

I'd do

location /api/ {
    proxy_set_header Host $host;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_pass http://somehost/;
}
  • Related