authentication – nginx auth_request:访问原始查询参数

前端之家收集整理的这篇文章主要介绍了authentication – nginx auth_request:访问原始查询参数前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

我想弄清楚是否可以将查询参数从原始URL转发到auth_request处理程序/服务?

用户应该能够将API标记添加查询参数,如下所示:
https://example.com/api/user?token=237263864823674238476

而不是通过标题或cookie.我可以在auth-service中以某种方式访问​​令牌参数吗?或者使用Nginx自定义标头中写入令牌查询参数?
到目前为止试过这个:

location = /api/user {
  auth_request /auth;
  proxy_set_header X-auth-token-from-query $arg_token;

  proxy_pass http://

/ auth端点没有获得X-auth-token-from-query标头但在返回200之后,上游代理确实获得了标头.

最佳答案
您很可能也希望将url(uri)传递给auth-request端点.你可以一次性做到这一点:

location = /api/auth {
  proxy_set_header X-Original-URI $request_uri;
  proxy_set_header X-Original-METHOD $request_method;
  proxy_pass_request_body off;
  proxy_set_header Content-Length "";

  proxy_pass http://

额外奖励:我也通过了这个方法! :田田:

原文链接:https://www.f2er.com/nginx/434509.html

猜你在找的Nginx相关文章