简体   繁体   中英

How to remove some part of path in nginx reverse proxy

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?

I'd do

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM