Nginx+tomcat Cluster, session sharing

Source: Internet
Author: User
Tags comparison memcached server port tomcat tomcat server

Comparison of the advantages and disadvantages between Apache and Nginx nginxtomcat cluster 1 jdktomcat installation 2 Boot Nginx 3 Modify Tomcat configuration tomcat61 Configuration 4 configuration conf nginxconf 5 test Nginx Configuration and restart 6 test load 61 Access Http127001test 62 If the Tomcat serverxml inside the context path is direct access to http127001 Serverxml context W Orkdir Apachetomcat Cluster Tomcat session sharing 1 use Memcached to save the session and then test 2 nginx configuration cluster upstream ip_hash static dynamic page separate picture anti-theft chain configuration 1 Nginx Configuration Second server 2 static dynamic page separate 3 picture anti-chain configuration Tomcat cluster project file Sync 1 currently Tomcat has not implemented a node update automatic Update so node function 2 How to make a file such as picture sharing, the different server access to the same address pictures and other resources

1 Comparison of the advantages and disadvantages of Apache and Nginx

Reference: http://www.cnblogs.com/huangye-dream/p/3550328.html 2 nginx+tomcat cluster 2.1 jdk, Tomcat installation 2.2 Start Nginx

Click Nginx.exe under E:\Program Files (x86) \nginx to see two nginx.exe processes

2.3 Modifying the Tomcat configuration

Two Tomcat, modify conf under Server.xml file 2.3.1 tomcat61 configuration separately:

<server port= "18005" shutdown= "shutdown" >

<connector port= "18080" protocol= "http/1.1" connectiontimeout= "20000" redirectport= "18443"/>

<connector port= "18009" protocol= "AJP/1.3" RedirectPort = "18443"/>

<engine name= "Catalina" defaulthost= "localhost" jvmroute= "TOMCAT1" >

In addition, add the settings: 2.3.2 tomcat62 configuration:

<server port= "28005" shutdown= "shutdown" >

<connector port= "28080" protocol= "http/1.1" connectiontimeout= "20000" redirectport= "28443"/>

<connector port= "28009" protocol= "AJP/1.3" RedirectPort = "28443"/>

<engine name= "Catalina" defaulthost= "localhost" jvmroute= "TOMCAT2" >

In addition, add the settings:

<context path= "/test" reloadable= "false" docbase= "E:\\program Files (x86) \\project\\Test" workdir= "E:\\program Files (x86) \\project\\temp "/> 
2.4 Configuring the nginx.conf under Conf

As follows

    Worker_processes 1;

    # add 1 error_log logs/error.log;
    Events {Worker_connections 1024;
        } http {include mime.types;
        Default_type Application/octet-stream;
        Sendfile on;
        Keepalive_timeout 65; # add 2 # poll upstream localhost {#每个请求按照访问ip based on weight (that is, Nginx's predecessor server or client 
                  IP) hash result distribution, #这样每个访客会固定访问一个后端服务器, can solve the session consistency problem #ip_hash;  
                  Server 192.168.0.45:18080 weight=1;  
        Server 192.168.0.45:28080 weight=1;
            } # Modify 3 server {Listen 80;

            server_name localhost;  
                Location/{Proxy_pass [http://localhost] (http://localhost/);  
                Proxy_redirect off;  
                Proxy_set_header Host $host;  
                Proxy_set_header X-real-ip $remote _addr; Proxy_set_header X-forwarDed-for $proxy _add_x_forwarded_for;  
                Client_max_body_size 10m;  
                Client_body_buffer_size 128k;  
                Proxy_connect_timeout 90;  
                Proxy_send_timeout 90;  
                Proxy_read_timeout 90;  
                Proxy_buffer_size 4k;  
                Proxy_buffers 4 32k;  
                Proxy_busy_buffers_size 64k; 
            Proxy_temp_file_write_size 64k;
            } error_page 502 503 504/50x.html;
            Location =/50x.html {root html;
 }        
        }

    }

Note: replace localhost with your domain name and replace 192.168.0.45 with your server's IP. 2.5 test Nginx configuration and restart

Test: Nginx-t
Restart: nginx-s Reload

2.6 Test Load 2.6.1 Access http://127.0.0.1/test/

To test, you can also add the Test2 folder, the tomcat62 in the Docbase=e:\program files (x86) \project\test to E:\Program files (x86) \project\test2, Then modify the interface to display the content to make a distinction. Observation results. 2.6.2 If the Tomcat server.xml inside the context path is "", you can directly access the HTTP://127.0.0.1/; 2.6.3 Tomcat Server.xml context in Workdir:

Workdir refers to the Tomcat parsing JSP into a Java file, and compiled into a class folder, set in the project folder, you can avoid porting to other places for the first time to read the JSP file needs to be re-parsed. General format: project folder \work; Of course, it's not right to delete it.

Reference: http://www.2cto.com/os/201407/317070.html
http://www.iteye.com/topic/676347

http://ari.iteye.com/blog/833153

http://aijuans.iteye.com/blog/2154373 3 apache+tomcat cluster

Http://www.cnblogs.com/qqzy168/archive/2013/08/03/3199237.html

Http://www.server110.com/apache/201312/4270.html 4 Tomcat session sharing 4.1 using memcached to save session ; (Test again later) 4.2 nginx configuration cluster words: Upstream Ip_hash 5 static, dynamic page separation, picture anti-theft chain configuration 5.1 nginx Configuration A second server

Set a second service (not required for load)

server {  
    #多监听         
    listen       801;  
    #主机名  
    server_name  localhost;  
    #WEB文件路径  
    root         e:/nginx;  
    #默认首页  
    index        hello.html;   

    #location/{  
    #    #这里相当于局部变量  
    #    root   e:/nginx;  
    #    index  hello.html;  
    #}  
}

Direct access to http://localhost:8666/can be accessed to hello.html (in E:/nginx) 5.2 Static, dynamic page separate 5.3 picture anti-theft chain configuration 6 Tomcat cluster project file synchronization

(Divide the same server and different server) 6.1 currently Tomcat has not implemented a node update, automatic updating so the function of the node;

http://bbs.csdn.net/topics/310202047/
But the same server can share the same disk file, Conf/server.xml host in the context set the same docbase; 6.2 How to make files such as picture sharing, that is, different server access to the same address of the picture and other resources

You can put the picture file in the same file, in the configuration server through Nginx to point to the corresponding folder file under the corresponding server, such as 5.1

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.