我想将所有/api/
(http://example.com/api/(的请求重定向到我的代理应用程序,并在此过程中删除/api
。我试过这个,但我在卷曲时得到一个 404。它没有到达应用程序,我认为这与rewrite
有关,但我不确定它是否正确。
location ~ ^/api {
rewrite ^/api/(.*) /$1 break;
proxy_pass http://127.0.0.1:8070;
}
以下内容在硬编码时有效。它将我重定向到我的应用程序/error
。
location = /api/error {
proxy_pass http://127.0.0.1:8070/error;
}
例如,我希望http://example.com/api/login
像这样http://example.com/login
命中我的代理应用程序。
这对我有用。$1$is_args$args
部分传递 URL 中/api
之后的所有内容。现在,当命中我的域时,example.com/api/something
会/something
传递给我的代理应用程序。
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 http://127.0.0.1:8070$1$is_args$args;
}