nginx 和 Tomcat 整合

来源:互联网 发布:预防域名攻击 编辑:程序博客网 时间:2024/05/17 08:39

1安装好jdk

2安装好tomcat

配置好两个tomcat  端口号改成不同的不让冲突 

3 安装好  nginx

4只需要 配置的是

nginx  的

nginx.cof  文件

给里面文件添加

http{

 

  1. upstream tomcat_server {  
  2.     server  localhost:8080;    //tomcat 的地址请求
  3.    server  localhost:8081;//
  4. }

 

  1. location / {  
  2.         proxy_pass  http://tomcat_server;   //这个名字和上面一样的
          }

}

这样就可以了

session   共享:

修改应用的web.xml

修改web应用里面WEB-INF目录下的web.xml文件,加入标签

<distributable/>

直接加在</web-app>之前就可以了

或者:

修改conf/web.xml文件,添加 distributable 属性,表示Tomcat要为此web应用复制 Session。在web.xml文件最后加上distributable,具体配置如下:
    <welcome-file-list>
        <welcome-file>index.html</welcome-file>
        <welcome-file>index.htm</welcome-file>
        <welcome-file>index.jsp</welcome-file>
    </welcome-file-list>
<distributable/>  #新加的distributable属性
</web-app>

这个是加入tomcat的session复制的,做tomcat集群必须需要这一步,否则用户的session就无法正常使用 



0 0