nginx使用proxy_pass反向代理时,session丢失的问题
2017-02-09 18:48
726 查看
原文地址:点击打开链接
以下为转载内容:
这2天在测试Nginx作为反向代理到Tomcat应用时,session丢失的问题。经过一系列查看官方文档和测试,发现如下:
1、如果只是host、端口转换,则session不会丢失。例如:
location /testwx {
proxy_pass http://127.0.0.1:8080/testwx;
}
通过浏览器访问http://127.0.0.1/testwx时,浏览器的cookie内有jsessionid。再次访问时,浏览器会发送当前的cookie。
2、如果路径也变化了,则需要设置cookie的路径转换,nginx.conf的配置如下
location /testwx {
proxy_pass http://127.0.0.1:8080/wx;
}
通过浏览器访问http://127.0.0.1/testwx时,浏览器的cookie内没有jsessionid。再次访问时,后台当然无法获取到cookie了。
详细看了文档:http://nginx.org/en/docs/http/ngx_http_proxy_module.html?&_ga=1.161910972.1696054694.1422417685#proxy_cookie_path
加上路径转换:proxy_cookie_path /wx /testwx;则可以将wx的cookie输出到testwx上,Tomcat的session正常了。正确的配置是:
location /testwx {
proxy_pass http://127.0.0.1:8080/wx;
proxy_cookie_path /wx /testwx;#这里的路径要注意对应关系
}
如果需要更复杂的路径转换可用通配符的方式进行转换,详情要查看http://nginx.org/en/docs/http/ngx_http_proxy_module.html?&_ga=1.161910972.1696054694.1422417685#proxy_cookie_path了。
以下为转载内容:
这2天在测试Nginx作为反向代理到Tomcat应用时,session丢失的问题。经过一系列查看官方文档和测试,发现如下:
1、如果只是host、端口转换,则session不会丢失。例如:
location /testwx {
proxy_pass http://127.0.0.1:8080/testwx;
}
通过浏览器访问http://127.0.0.1/testwx时,浏览器的cookie内有jsessionid。再次访问时,浏览器会发送当前的cookie。
2、如果路径也变化了,则需要设置cookie的路径转换,nginx.conf的配置如下
location /testwx {
proxy_pass http://127.0.0.1:8080/wx;
}
通过浏览器访问http://127.0.0.1/testwx时,浏览器的cookie内没有jsessionid。再次访问时,后台当然无法获取到cookie了。
详细看了文档:http://nginx.org/en/docs/http/ngx_http_proxy_module.html?&_ga=1.161910972.1696054694.1422417685#proxy_cookie_path
加上路径转换:proxy_cookie_path /wx /testwx;则可以将wx的cookie输出到testwx上,Tomcat的session正常了。正确的配置是:
location /testwx {
proxy_pass http://127.0.0.1:8080/wx;
proxy_cookie_path /wx /testwx;#这里的路径要注意对应关系
}
如果需要更复杂的路径转换可用通配符的方式进行转换,详情要查看http://nginx.org/en/docs/http/ngx_http_proxy_module.html?&_ga=1.161910972.1696054694.1422417685#proxy_cookie_path了。
相关文章推荐
- 解决nginx使用proxy_pass反向代理时,session丢失的问题
- 解决nginx使用proxy_pass反向代理时,session丢失的问题
- nginx使用proxy_pass反向代理时cookie丢失问题解决方案
- 解决nginx使用proxy_pass反向代理时,cookie丢失的问题
- 解决nginx使用proxy_pass反向代理时,cookie丢失的问题
- 解决nginx中proxy_pass到tomcat的session丢失问题
- 解决nginx中proxy_pass到tomcat的session丢失问题
- 解决nginx中proxy_pass到tomcat的session丢失问题:补充
- 解决nginx中proxy_pass到tomcat的session丢失问题
- 解决nginx中proxy_pass到tomcat的session丢失问题
- nginx反向代理proxy_set_header自定义header头无效的问题
- Nginx 反向代理实现 分布式 国际化 tomcat session 问题
- nginx反向代理tomcat会出现session失效问题
- 用nginx反向代理Jenkins遇到的testForReverseProxySetup问题
- nginx反向代理(proxy_pass)tomcat的过程中,session失效的问题解决
- nginx中proxy_pass到tomcat的session丢失
- 关于nginx反向代理后session问题
- 【Nginx的坑】nginx反向代理proxy_set_header自定义header头无效的问题
- Nginx 的使用配置并利用nginx 反向代理解决跨域问题
- Mac下使用nginx反向代理服务器解决资源跨域问题