Nginx load balances multiple tomcat servers

Using nginx for load balancing in the windows environment can only be used for testing and practice. In the production environment, there will be problems, because it is mainly due to the limitation of windows on the number of connections of 1024, and the support for epoll is not very good, so Just learn to introduce how to configure multiple tomcat servers.
The tomcat server runs locally. For example, if you want to start two servers or more, let's say, copy the original tomcat file directory to the hard disk and name it tomcat-8090.
Then enter tomcat-8090 and modify it in the conf directory. The main modification of sever.xml, the previous one was 8005, now it is modified to 8006, the previous connector was 8080, it should be 8090, the previous one was 8009, and it was changed to 8010
<Server port="8006" shutdown="SHUTDOWN">  
    <Connector port="8090" protocol="HTTP/1.1"
               connectionTimeout="20000"
               redirectPort="8443" />
 <Connector port="8010" protocol="AJP/1.3" redirectPort="8443"/>

After that, modify startup.bat and shutdown.bat in the bin directory and
add set CATALINA_HOME=F:\apache-tomcat-6.0.35-8090 in the first sentence of the bin directory.
For linux environment, modify startup.sh shutdown.sh
and add the first sentence After setting it up for export CATALINA_HOME=/opt/***

, you can start startup.bat on the console to see the effect.

After that, download nginx and add it to the conf configuration file

    upstream localhost {     
    #Assign the request to each backend tomcat according to ip calculation, many people mistakenly think that the session problem can be solved, but it can't.     
    #The same machine in the case of multiple networks, routing switching, ip may be different     
    #ip_hash;      
    server localhost:8090;     
    server localhost:8080;     
    }  

  server {
        listen       80;
        server_name  localhost;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        location / {
			proxy_pass http://localhost;
            root   html;
            index  index.html index.htm;
        }
  }

Then open the corresponding applications and services, and visit the address bar information
http://localhost/Second/user/index to see
[img][/img]

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326327484&siteId=291194637