windows系统下配置Nginx反向代理多tomcat共享session

2021-05-30 07:23

阅读:518

YPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd">

标签:lis   nbsp   sel   ges   jaxp   begin   pac   jsp   ice   

 

nginx、tomcat下载安装本篇不提了,直接说步骤:

1 配置nginx配置文件:

nginx下conf文件夹中的nginx.conf 添加下面代码,

  upstream web_apps{
            server      127.0.0.1:8080 weight=1;
            server      127.0.0.1:8989 weight=1;
        }
server {
            listen 80;
            server_name  localhost 127.0.0.1;

            proxy_set_header Host $host;
            proxy_set_header X-Forwarded-Host $host;
            proxy_set_header X-Forwarded-Server $host;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_set_header X-Requested-For $remote_addr;
            proxy_set_header REMOTE-HOST $remote_addr;

            proxy_http_version 1.1;
            proxy_set_header Upgrade $http_upgrade;
            proxy_set_header Connection "upgrade";


            location / {
			root	html;
			index	index.html;
			 proxy_pass      http://web_apps;
			proxy_connect_timeout 600;
			proxy_read_timeout 600;
            }

    }

  

2配置tomcat 配置文件:

修改tomcat下conf中 server.xml

多个tomcat 中有3地方要不能冲突:

    

 port可以设大一点。

  然后每个加上tomcat自带的session同步 找到关键句下面添加

  然后把tomcat初始页码换一下方便测试效果,在apache-tomcat\webapps\ROOT 更改index.jsp内容为

 test
        SessionID is 
        
SessionIP is
SessionPort is

tomcat_8080

  然后分别启动tomcat 和nginx 。

  直接输入localhost就如下图

技术图片

或者是这样:

技术图片

tomcat服务器会被nginx切换 但sessionID没有变。

另外说个nginx个操作指令 :cmd黑窗口进入nginx目录输入  nginx -s reload 会重新载入nginx的配置文件,不用重启nginx.

 如果出现异常先去看log文件 tomcat和nginx日志很详细。比如我遇到的:

19-Jun-2019 10:42:12.779 警告 [main] org.apache.catalina.startup.Catalina.load Unable to load server configuration from [D:\apache-tomcat-9.0.17\conf\server.xml]
org.xml.sax.SAXParseException; systemId: file:/D:/apache-tomcat-9.0.17/conf/server.xml; lineNumber: 154; columnNumber: 113; Error at line [154] column [113]: [org.apache.catalina.tribes.group.interceptors.MessageDispatch15Interceptor]
at org.apache.tomcat.util.digester.Digester.createSAXException(Digester.java:1855)
at org.apache.tomcat.util.digester.Digester.createSAXException(Digester.java:1887)
at org.apache.tomcat.util.digester.Digester.startElement(Digester.java:1176)
at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.startElement(AbstractSAXParser.java:509)
at com.sun.org.apache.xerces.internal.parsers.AbstractXMLDocumentParser.emptyElement(AbstractXMLDocumentParser.java:182)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanStartElement(XMLDocumentFragmentScannerImpl.java:1339)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDriver.next(XMLDocumentFragmentScannerImpl.java:2784)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(XMLDocumentScannerImpl.java:602)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(XMLDocumentFragmentScannerImpl.java:505)
at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:842)
at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:771)
at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(XMLParser.java:141)
at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(AbstractSAXParser.java:1213)
at com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSAXParser.parse(SAXParserImpl.java:643)
at org.apache.tomcat.util.digester.Digester.parse(Digester.java:1431)
at org.apache.catalina.startup.Catalina.load(Catalina.java:567)
at org.apache.catalina.startup.Catalina.load(Catalina.java:608)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.apache.catalina.startup.Bootstrap.load(Bootstrap.java:306)
at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:491)
Caused by: java.lang.ClassNotFoundException: org.apache.catalina.tribes.group.interceptors.MessageDispatch15Interceptor
at java.net.URLClassLoader.findClass(URLClassLoader.java:382)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
at org.apache.tomcat.util.digester.ObjectCreateRule.begin(ObjectCreateRule.java:115)
at org.apache.tomcat.util.digester.Digester.startElement(Digester.java:1173)
... 20 more

这个包已过时不在了,配上去肯定不行。。

参考博客:

https://www.cnblogs.com/beyang/p/9122406.html

https://blog.csdn.net/qq_23832313/article/details/83578813

over~

windows系统下配置Nginx反向代理多tomcat共享session

标签:lis   nbsp   sel   ges   jaxp   begin   pac   jsp   ice   

原文地址:https://www.cnblogs.com/xddbky/p/11050446.html


评论


亲,登录后才可以留言!