其他
nginx搭建tomcat分布式集群
1. nginx使用80端口,所有对服务器80端口的访问都被nginx拦截。例:
127.0.0.1 www.jthinking.com 127.0.0.1 admin.jthinking.com 127.0.0.1 resource.jthinking.com2. 在nginx的nginx.conf配置文件中增加配置。例:
----------------------------------------------------
#前台服务器,当访问域名为www.jthinking.com时,转去访问本机的60060端口,增加一个tomcat服务器监听此端口
server { listen 80; server_name www.jthinking.com; #charset koi8-r; #access_log logs/host.access.log main; 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; location / { proxy_pass http://127.0.0.1:60060; proxy_connect_timeout 600; proxy_read_timeout 600; } }#后台服务器,当访问域名为admin.jthinking.com时,转去访问本机的60061端口,增加一个tomcat服务器监听此端口
server { listen 80; server_name admin.jthinking.com; #charset koi8-r; #access_log logs/host.access.log main; 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; location / { proxy_pass http://127.0.0.1:60061; proxy_connect_timeout 600; proxy_read_timeout 600; } }#静态资源服务器,当访问域名为resource.test.com下的静态资源时,nginx直接将资源返回,无需通过tomcat,效率高
server { listen 80; server_name resource.jthinking.com; #charset koi8-r; #access_log logs/host.access.log main; 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; location / { root /root/Website/Resource; } }----------------------------------------------------
3. 修改Tomcat服务器配置server.xml
修改三处端口(每台主机的端口号的范围为0到65535)例:
第一个Tomcat:
<Server port="60050" shutdown="SHUTDOWN"> <Connector port="60060" protocol="HTTP/1.1" /> <Connector port="60070" protocol="AJP/1.3" />第二个Tomcat:
<Server port="60051" shutdown="SHUTDOWN"> <Connector port="60061" protocol="HTTP/1.1" /> <Connector port="60071" protocol="AJP/1.3" />......
在同一台主机上的每个Tomcat的每个端口都不允许重复。