如何在 url 中使用带访问令牌的 nginx 代理?

How to use nginx proxy with access token in url?

我 运行 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=";
    }
}

这里我想从 url 中取出 <token> 并将剩余的端点传递到我的 proxy_pass 服务器。请帮助我。

谢谢@Richard,您的建议有助于解决我的问题。为了其他人的参考,更新nginx.conf文件:-

server {
    listen 80;
    location / {
        rewrite ^/[^/]+(/.*)$  break;
        proxy_pass         http://backend;
        proxy_set_header Authorization "Basic safdadfWU6cdfdvcmQ=";
    }
}

现在我可以使用 url 作为 http://IP:PORT/<token>/endpoint 并且应该作为 http://backend/endpoint

代理到 url