tomcat - Nginx - 如何从 header 中获取值并将其设置到 cookie 中?

标签 tomcat nginx url-rewriting session-cookies

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

最佳答案

试试这个:

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>;

关于tomcat - Nginx - 如何从 header 中获取值并将其设置到 cookie 中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53542525/

相关文章:

tomcat - HAProxy - URL 重定向和重写

docker - 使用 Dockerfile 创建 war 文件并在 tomcat 中部署

google-app-engine - 从 GAE 移植到 TomCat 或其他 servlet 服务器

ubuntu - 使用 2 级代理的 Nginx Web 服务器

php - Nginx/php fpm CORS 请求未通过

angular - 在 tomcat 8 服务器上重写 Angular 4 的 URL

ajax - 如何将 url 重定向到另一个

java - apache tiles 2 JSPException 包括路径

apache - 在 apache 服务器和 tomcat 之间设置代理的问题

python - Nginx WebSocket 代理不断获取 HTTP 301 重定向