【问题标题】:nginx auth_request with cookie带有 cookie 的 nginx auth_request
【发布时间】:2019-04-18 17:52:08
【问题描述】:

可能是 this question 的副本,但它没有答案,我在那里尝试了该建议,但无法使其发挥作用。我需要在代理之前授权每个请求,我试图通过 cookie 来做到这一点,但是 cookie 值没有在任何后续请求上设置。互联网上的大多数地方都推荐如下内容

server {
  auth_request /auth;

  location /auth {
    internal;
    proxy_pass http://auth:8080/auth;
    auth_request_set $saved_set_cookie $upstream_http_set_cookie;
    add_header Set-Cookie $saved_set_cookie;
  }
}

但这似乎不起作用。如上问题所述,我什至尝试使用自定义标题来查看是否可以看到它,但它不起作用。

server {
  auth_request /auth;

  location /auth {
    internal;
    proxy_pass http://auth:8080/auth;
    auth_request_set $saved_set_cookie $upstream_http_set_cookie;
    add_header X-COOKIE-TEST $saved_set_cookie;
  }
}

如果我直接访问身份验证服务器,我确实会看到 cookie 已设置

【问题讨论】:

    标签: authentication nginx cookies


    【解决方案1】:

    https://github.com/nginxinc/NGINX-Demos/blob/331fd357e6e1813b5d41aed48880cf274d31dcee/oauth2-token-introspection-oss/frontend.conf#L29 找到了一个可行的解决方案,它真的很简单(Nginx 1.18.0):

      location / {
        auth_request /authz;
        auth_request_set $new_cookie $sent_http_set_cookie; # use sent_http_*, not upstream_http_*
        add_header Set-Cookie $new_cookie;
        add_header X-Test $sent_http_set_cookie;            # it's even working directly
      }
    

    【讨论】:

      猜你喜欢
      • 2017-03-18
      • 2020-01-31
      • 2018-03-08
      • 2018-06-12
      • 1970-01-01
      • 2015-10-17
      • 1970-01-01
      • 1970-01-01
      • 2013-10-22
      相关资源
      最近更新 更多