【发布时间】:2020-08-12 22:00:35
【问题描述】:
我正在运行 nginx 作为后端服务的代理。我想使用 url 作为http://IP:PORT/<token>/endpoint 并且应该代理到 url 作为http://backend/endpoint
nginx.conf 文件:-
server {
listen 80;
location / {
proxy_pass http://backend;
proxy_set_header Authorization "Basic safdadfWU6cdfdvcmQ=";
}
}
在这里,我想将<token> 从 url 中取出,并将剩余的端点传递给我的 proxy_pass 服务器。请帮助我。
【问题讨论】:
-
尝试:
rewrite ^/[^/]+(/.*)$ $1 break;从 URI 中删除第一个路径元素。 -
感谢@RichardSmith 的回复,您能告诉我应该将
rewrite ^/[^/]+(/.*)$ $1 break;行放在我的nginx.conf 文件中的哪个位置吗?对不起,我对 nginx 代理和配置很天真。 -
在与 proxy_pass 语句相同的位置块内。
标签: nginx reverse-proxy