【问题标题】:Nginx - how to take value from header and set it into cookie?Nginx - 如何从标头中获取值并将其设置为 cookie?
【发布时间】:2018-11-30 04:13:14
【问题描述】:

在 nginx 上,我需要检查客户端是否有 jsessionid cookie,然后将所有内容按原样代理到 tomcat,但如果没有 cookie,则从标头 x-auth-token 中获取值并将其设置为 jsessionid cookie,然后代理一切到tomcat。

【问题讨论】:

    标签: tomcat nginx url-rewriting session-cookies


    【解决方案1】:

    试试这个:

    location / {
        if ($cookie_JSESSIONID = "") {
            add_header Set-Cookie JSESSIONID=$http_x_auth_token;
        }
        proxy_pass <proto://tomcat_server_address:port>;
    }
    

    如果你的tomcat域和site域不同,可能需要在proxy_pass参数前添加额外的参数:

    proxy_set_header Host <tomcat_domain>;
    proxy_cookie_domain <tomcat_domain> <site_domain>;
    

    【讨论】:

      猜你喜欢
      • 2021-07-27
      • 2020-11-28
      • 1970-01-01
      • 2014-07-21
      • 1970-01-01
      • 1970-01-01
      • 2012-08-17
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多