使用Spring MVC无法在Tomcat和Nginx proxypass中保持HTTP会话 [英] Http session couldn't hold in Tomcat and nginx proxypass using Spring mvc

查看:72
本文介绍了使用Spring MVC无法在Tomcat和Nginx proxypass中保持HTTP会话的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Tomcat 7,并使用nginx 1.5.7作为负载平衡器(在Windows 8上).我像这样配置nginx服务器.

I am using Tomcat 7 and using nginx 1.5.7 as a load-balancer(on Windows 8). I configurated nginx server like this.

server {
    listen          80;
    server_name     www.something.com something.com;
    location / {
        proxy_pass http://127.0.0.1:8080/webapp/;
    }
}

我也重定向到我的主机"文件中:127.0.0.1 www.something.com

Also I redirect in my "hosts" file: 127.0.0.1 www.something.com

但是在登录或通过发布进行任何会话操作之后,我的web应用程序中没有会话保持,这就像没有会话参数一样.

But after login or any session operation via post, there is no session holding in my webapp, It is behaving like no session parameters.

通过我尝试在web.xml文件中添加的方式

By the way i tried to add in web.xml file

<session-config>
      <tracking-mode>COOKIE</tracking-mode>
</session-config>

但是什么都没有改变.

那么在这种状态下是什么问题?

So what is the problem in this state?

感谢您的帮助.

推荐答案

您已在代理(/->/webapp)中更改了Web应用程序的路径.通常这是一个坏主意,因为它会破坏您需要修复的一堆东西.在这种情况下,可能是cookie路径是您的直接问题.要解决此问题,您需要使用proxy_cookie_path指令.修复该问题后,还会发现其他问题.

You have changed the path to the web application in the proxy (/ -> /webapp). This is generally a bad idea as it breaks a whole bunch of stuff that you then need to fix. In this case it is probably the cookie path that is your immediate problem. To fix that you need to use the proxy_cookie_path directive. Once you fix that expect to find other problems.

实际上,最好将Web应用程序重新部署为ROOT Web应用程序,以便您的proxy_pass指令变为proxy_Pass http://127.0.0.1:8080/;

You'd actually be better off redeploying your web application as the ROOT web app so that your proxy_pass directive becomes proxy_Pass http://127.0.0.1:8080/;

这篇关于使用Spring MVC无法在Tomcat和Nginx proxypass中保持HTTP会话的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆