'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 ?
Solution 1:[1]
I'd do
location /api/ {
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_pass http://somehost/;
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Hans Kilian |
