如何访问 nginx 位置内的查询参数?

问题描述 投票:0回答:0

我正在尝试设置一个 nginx auth_request 位置,它可以使用两个选项验证用户请求,默认选项在直接发送到 proxy_pass 的客户端标头请求中使用授权标头。第一个按预期工作。第二个是检测客户端请求中是否有

token
查询参数,改变验证路径和代理方式。但是,似乎本应具有此值的变量
query_parameter
args
arg_token
在 auth 位置内都是空的。下面是我的 nginx-config 配置图。

apiVersion: v1
kind: ConfigMap
metadata:
  name: nginx-config
  namespace: nginx-ingress
data:
  location-snippets: "  
    auth_request /auth;
  server-snippets: " 
    location = /auth {      
      if ($request_method = 'OPTIONS') { return 204; } 
      if ($request_uri !~ '/api/v') { return 200; } # All none api requests 

      set $method POST;
      set $backend_path verify?tenant=airqo;

      if ($arg_token) {
        set $method GET;
        set $backend_path tokens/$arg_token/verify;
      }

      internal;
      resolver                kube-dns.kube-system.svc.cluster.local valid=5s;
      proxy_method            $method;
      proxy_pass              http://auth.default.svc.cluster.local:3000/api/v1/users/$backend_path;
      proxy_pass_request_body off;
      proxy_set_header        Content-Length '';
      proxy_set_header        X-Original-URI $request_uri;
    }"

示例客户请求可能如下所示:

GET: /api/v1/apples?token=123
我可能会出错,我该如何解决?

nginx variables nginx-ingress nginx-config nginx-location
© www.soinside.com 2019 - 2024. All rights reserved.