I want to set pass_proxy in nginx as follows. (I used rewrite statem.)
example.com/api/ -> example.com/api
exmaple.com/api ->example.com/api
Below is my code.
==============================================
server {
listen 80;
server_name example.com;
location / {
root html;
index index.html index.htm;
}
location /api {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header HOST $host;
proxy_set_header X-NginX-Proxy true;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
rewrite ^/api(.*)$ $1?$args break;
# rewrite ^/api(.*)/$ /$1 break;
# rewrite ^/(.*)/$ /$1 permanent;
proxy_pass http://api.com;
proxy_redirect off;
}
}
========================================
Both should be moved to the site set in pass_proxy.
but, makes it http://example.com/api/ via 301 redirect.
I want /api, without trailing slash to go to another location.
Here's what I tried:
rewrite ^/(.*)/$ /$1 permanent;
In the following document, when proxy_pass is used,
it is said that a slash is automatically added at the end, but is it impossible to get rid of this?
https://nginx.org/en/docs/http/ngx_http_core_module.html#location
Edited 1 time(s). Last edit at 12/07/2022 11:18PM by starnge_proxy.