【问题标题】:Push http header into cookie将 http 标头推入 cookie
【发布时间】:2017-02-26 23:15:33
【问题描述】:

我正在尝试使用从 apache 2.4 到 nginx 的 cookie 跨代理传播 http 标头。

Apache 仅用于针对 Active Directory 进行 kerberos 身份验证。由于 AD 身份验证添加到每个 get 请求的开销,我想限制身份验证。这个想法是设置一个在 x 时间后过期的 cookie,如果 cookie 不存在,则仅通过 apache 执行身份验证。 此外,我希望 apache 的 remote_user 对 nginx 可用。

Nginx 监听 80 端口,并在 81 端口(同一主机)上向 apache 发出 auth 子请求

我可以在 apache 中设置 http 标头,但是这些在 nginx 领域会丢失。

我首先尝试从 nginx 读取我感兴趣的特定 http 标头,但是一旦将请求转移到 nginx,我就看不到它,尽管我可以看到它们是在 apache 端设置的。

我的第二个想法是把我感兴趣的header推送到一个服务器cookie中,然后在nginx端提取,但是cookie值总是空的。

在我的 apache conf 中:

RewriteRule .* - [E=PROXY_USER:%{LA-U:REMOTE_USER}] 
Header add X-Auth-User %{PROXY_USER}e 

我可以在 apache 端看到该标题,但在 nginx 端没有。

尝试将数据泵入 apache 中的 cookie:

RewriteCond %{LA-U:REMOTE_USER} (.*)
RewriteRule ^/ - [env=COOKIE1:%1]
RewriteRule .* - [CO=acaprox:tst=%{COOKIE1}e:.my-domain.com:300:/] [R=307,L]

这种方法的问题在于 test 的值总是空的。

我也尝试重用环境变量,我可以成功推入标头,进入cookie,但它也总是空的:

 RewriteRule .* - [CO=cookietest:tst=%{ENV:PROXY_USER}:.my-domain.com:300:/] [R=307,L]

很明显,我在这个领域没有太多经验。

【问题讨论】:

    标签: apache mod-rewrite nginx apache2


    【解决方案1】:

    这个问题似乎与 remote_user 有关,其他变量适用于我使用的方法。

    我的解决方案是在上游代理(即 x-remote-user)设置一个额外的标头,然后如果 auth_request 成功则从中提取值。

    auth_request $user $upstream_http_x_remote_user
    

    然后可以将 $user 变量推送到 cookie 中

    【讨论】:

      猜你喜欢
      • 2016-11-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-11-29
      • 2013-02-08
      • 2016-07-19
      相关资源
      最近更新 更多