Nginx reverse proxy load balancing and session sharing

  With the increasing level of social development, science and technology, the Internet is playing an increasingly important role in people's daily lives, while the problem of network security, network reliability have become increasingly prominent. Traditional single service architecture can not meet the modern needs of users. And it was followed by a variety of distributed / clustered service architecture model. Achieve multiple services together to provide services. The most common is Nginx proxy technology.

  After the user's request reaches the nginx proxy server, depending on the strategy to be forwarded to a different server, to achieve load balancing.

Tomcat using a plurality of instances arranged server.xml

  <-! Connector thread pool used ->

Review: different examples using different port numbers

<1>-----------------------------------------------------------------------------------------------------------------------------

<Connector executor="tomcatThreadPool" port="8081" protocol="org.apache.coyote.http11.Http11AprProtocol"
connectionTimeout="30000" redirectPort="8443" URIEncoding="UTF-8" enableLookups="false"
connectionUploadTimeout="150000" acceptCount="300" keepAliveTimeout="120000"/>

<Connector port="8009" protocol="AJP/1.3" redirectPort="8443"/>

<2>-----------------------------------------------------------------------------------------------------------------------------

<Connector executor="tomcatThreadPool" port="8082" protocol="org.apache.coyote.http11.Http11AprProtocol"
connectionTimeout="30000" redirectPort="8443" URIEncoding="UTF-8" enableLookups="false" 
connectionUploadTimeout="150000" acceptCount="300" keepAliveTimeout="120000"/>

<Connector port="8019" protocol="AJP/1.3" redirectPort="8443"/>

...

Arranged in a plurality of environment variables CATALINA_HOME, respectively corresponding to the respective tomcat example, and the need to modify catalina.bat corresponds to a respective startup.bat CATALINA_HOME names and environment variables.

Deployed project.

Configure Nginx: in. . Nginx / conf / nginx.conf, open and configure nginx.conf

#tomcat cluster configuration
upstream myapp {
# myapp is the name of the cluster, the low version (before 8.5.31) of tomcat will verify the forwarding address name constituted, can not exist underscore "_" and other special characters, otherwise it will produce 400 wrong;
#weight access probability according to size determines the weight value;

The hash value is assigned #ip_hash client ip address will be forwarded Server (ip is fixed due to this can be achieved using the session shared Further redis, springSession session sharing mechanism may also be implemented.);

#fair speed distribution of the response speed of the server;

# url_hash;

# Default polling mode
server 127.0.0.1:8081; # tomcat1 Configure
Server 127.0.0.1:8082;
#server weight = 127.0.0.1:8083. 6;
# Server 192.168.1.108:88 weight =. 3; # tomcat2 disposed
}
Server {
the listen 9090 ; # listening port
server_name localhost ; ip address #nginx services
LOCATION / {
proxy_pass HTTP: // myapp;
proxy_redirect default;
proxy_set_header Host $ Host: $ SERVER_PORT;
}
}

Respectively, start the application service, and then start nginx service

Finally, access to HTTP: // L ocalhost: 9090 / ( project name)

 

Guess you like

Origin www.cnblogs.com/jasonma/p/11287880.html