小编kol*_*oly的帖子

nginx,为什么不能在 if 部分使用 auth_request

我正在尝试仅针对 Nginx 中的 POST 方法发出自定义身份验证请求。我找到了 auth_request 模块,所以我写了这样的东西:

location /api/books {
  if ($request_method = GET) {
     proxy_pass http://bookservice;
  }
  auth_request /api/auth;
  proxy_pass http://bookservice;
}
location /api/auth {
  proxy_pass http://authservice;
}
Run Code Online (Sandbox Code Playgroud)

bookservice 和 authservice 是两个上游。我第一次尝试这个,它不起作用:每次有 GET /api/books 时,它都会触发对身份验证服务的子请求。预期的行为是:当它是 GET /api/books 时,它不会向 auth 服务发出子请求,否则,它会向 auth 服务发出子请求。

所以我写了类似的东西:

location /api/books {
  if ($request_method = GET) {
     proxy_pass http://bookservice;
  }
  if ($request_method = POST) {
    auth_request /api/auth;
    proxy_pass http://bookservice;
  }
}
location /api/auth {
  proxy_pass http://authservice;
}
Run Code Online (Sandbox Code Playgroud)

但是当重新加载配置时,它说:“auth_request”指令在这里是不允许的。

我知道 auth_request 不能在 if 中,它只能在位置、服务器、http 中。但是如何实现我的目标,为什么不能在if里面应用呢?

java nginx

8
推荐指数
1
解决办法
1912
查看次数

Istio VirtualService和Kubernetes Service有什么区别?

据我了解,Istio VirtualService是一种抽象的事物,它试图向实际的实现中添加接口,例如Kubernetes中的服务或Consul中的类似东西。

我的问题是:

当使用Kubernetes作为Istio的基础平台时,Istio VirtualService和Kubernetes Service有什么区别?还是一样?

kubernetes istio

5
推荐指数
3
解决办法
1433
查看次数

标签 统计

istio ×1

java ×1

kubernetes ×1

nginx ×1