今天遇到一个问题:
nginx反向代理tomcat
locattion / {
proxy_pass http:
//192
.168.1.12:11080
/iloadsdev-web/
;
proxy_set_header Host $host;
proxy_set_header Remote_Addr $remote_addr;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
这时候我们访问页面其实都是到tomcat,我们通过浏览器查看seesion,发现只要刷新一下页面seesion就会变,解决办法如下:
location / {
proxy_pass http:
//192
.168.1.12:11080
/
iloadsdev-web
/;
proxy_cookie_path
/
iloadsdev-web
//; #加个反向代理cookie路径设置
proxy_set_header Host $host;
proxy_set_header Remote_Addr $remote_addr;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
还有一种解决办法就是proxy_pass http:
//192
.168.1.12:11080
/
iloadsdev-web
;
把/iloadsdev-web/ 最后个‘/‘ 去掉,但是这样做不好,会影响访问
真不行就到tomcat下增加如下:
apache-tomcat/config/server.xml
......
<Host name="openplat.wangdaizhijia.com" appBase=""
unpackWARs="true" autoDeploy="true"
xmlValidation="false" xmlNamespaceAware="false">
<Context path="" docBase="/wdzj/java/tomcat/apache-tomcatioadsdev-web/ioadsdev-web" debug="0"/>
<Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
prefix="openplat_access_log." suffix=".txt"
pattern="%{X-Real_IP}i %D %h %l %u %t %r %s %b %{Referer}i %{User-Agent}i" resolveHosts="false" />
</Host>
......