Nginx+Tomcat在Windows下做负载均衡Word下载.docx
《Nginx+Tomcat在Windows下做负载均衡Word下载.docx》由会员分享,可在线阅读,更多相关《Nginx+Tomcat在Windows下做负载均衡Word下载.docx(8页珍藏版)》请在冰豆网上搜索。
>
为<
8006"
,修改其中的
<
Connectorport="
8080"
protocol="
HTTP/1.1"
connectionTimeout="
20000"
redirectPort="
8443"
/>
为
8088"
修改后的文件如下:
?
xmlversion='
1.0'
encoding='
utf-8'
!
--
LicensedtotheApacheSoftwareFoundation(ASF)underoneormore
contributorlicenseagreements.
SeetheNOTICEfiledistributedwith
thisworkforadditionalinformationregardingcopyrightownership.
TheASFlicensesthisfiletoYouundertheApacheLicense,Version2.0
(the"
License"
);
youmaynotusethisfileexceptincompliancewith
theLicense.
YoumayobtainacopyoftheLicenseat
http:
//www.apache.org/licenses/LICENSE-2.0
Unlessrequiredbyapplicablelaworagreedtoinwriting,software
distributedundertheLicenseisdistributedonan"
ASIS"
BASIS,
WITHOUTWARRANTIESORCONDITIONSOFANYKIND,eitherexpressorimplied.
SeetheLicenseforthespecificlanguagegoverningpermissionsand
limitationsundertheLicense.
-->
--Note:
A"
Server"
isnotitselfa"
Container"
soyoumaynot
definesubcomponentssuchas"
Valves"
atthislevel.
Documentationat/docs/config/server.html
<
--APRlibraryloader.Documentationat/docs/apr.html-->
ListenerclassName="
org.apache.catalina.core.AprLifecycleListener"
SSLEngine="
on"
--InitializeJasperpriortowebappsareloaded.Documentationat/docs/jasper-howto.html-->
org.apache.catalina.core.JasperListener"
--Preventmemoryleaksduetouseofparticularjava/javaxAPIs-->
org.apache.catalina.core.JreMemoryLeakPreventionListener"
--JMXSupportfortheTomcatserver.Documentationat/docs/non-existent.html-->
org.apache.catalina.mbeans.ServerLifecycleListener"
org.apache.catalina.mbeans.GlobalResourcesLifecycleListener"
--GlobalJNDIresources
Documentationat/docs/jndi-resources-howto.html
-->
GlobalNamingResources>
--Editableuserdatabasethatcanalsobeusedby
UserDatabaseRealmtoauthenticateusers
Resourcename="
UserDatabase"
auth="
type="
org.apache.catalina.UserDatabase"
description="
Userdatabasethatcanbeupdatedandsaved"
factory="
org.apache.catalina.users.MemoryUserDatabaseFactory"
pathname="
conf/tomcat-users.xml"
/GlobalNamingResources>
--A"
Service"
isacollectionofoneormore"
Connectors"
thatshare
asingle"
Note:
soyoumaynotdefinesubcomponentssuchas"
Documentationat/docs/config/service.html
Servicename="
Catalina"
--Theconnectorscanuseasharedexecutor,youcandefineoneormorenamedthreadpools-->
Executorname="
tomcatThreadPool"
namePrefix="
catalina-exec-"
maxThreads="
150"
minSpareThreads="
4"
/>
Connector"
representsanendpointbywhichrequestsarereceived
andresponsesarereturned.Documentationat:
JavaHTTPConnector:
/docs/config/http.html(blocking&
non-blocking)
JavaAJP
Connector:
/docs/config/ajp.html
APR(HTTP/AJP)Connector:
/docs/apr.html
Defineanon-SSLHTTP/1.1Connectoronport8080
usingthesharedthreadpool-->
Connectorexecutor="
port="
--DefineaSSLHTTP/1.1Connectoronport8443
ThisconnectorusestheJSSEconfiguration,whenusingAPR,the
connectorshouldbeusingtheOpenSSLstyleconfiguration
describedintheAPRdocumentation-->
SSLEnabled="
true"
scheme="
https"
secure="
clientAuth="
false"
sslProtocol="
TLS"
--DefineanAJP1.3Connectoronport8009-->
8009"
AJP/1.3"
--AnEnginerepresentstheentrypoint(withinCatalina)thatprocesses
everyrequest.
TheEngineimplementationforTomcatstandalone
analyzestheHTTPheadersincludedwiththerequest,andpassesthem
ontotheappropriateHost(virtualhost).
Documentationat/docs/config/engine.html-->
--YoushouldsetjvmRoutetosupportload-balancingviaAJPie:
Enginename="
defaultHost="
localhost"
jvmRoute="
jvm1"
--Forclustering,pleasetakealookatdocumentationat:
/docs/cluster-howto.html
(simplehowto)
/docs/config/cluster.html(referencedocumentation)-->
ClusterclassName="
org.apache.catalina.ha.tcp.SimpleTcpCluster"
--Therequestdumpervalvedumpsusefuldebugginginformationabout
therequestandresponsedatareceivedandsentbyTomcat.
Documentationat:
/docs/config/valve.html-->
ValveclassName="
org.apache.catalina.valves.RequestDumperValve"
--ThisRealmusestheUserDatabaseconfiguredintheglobalJNDI
resourcesunderthekey"
.
Anyedits
thatareperformedagainstthisUserDatabaseareimmediately
availableforusebytheRealm.
RealmclassName="
org.apache.catalina.realm.UserDatabaseRealm"
resourceName="
--Definethedefaultvirtualhost
XMLSchemavalidationwillnotworkwithXerces2.2.
Hostname="
appBase="
webapps"
unpackWARs="
autoDeploy="
xmlValidation="
xmlNamespaceAware="
--SingleSignOnvalve,shareauthenticationbetweenwebapplications
org.apache.catalina.authenticator.SingleSignOn"
--Accesslogprocessesallexample.
org.apache.catalina.valves.AccessLogValve"
directory="
logs"
prefix="
localhost_access_log."
suffix="
.txt"
pattern="
common"
resolveHosts="
/Host>
/Engine>
/Service>
/Server>
5.修改Nginx配置文件nginx.conf,该文件位于Nginx根目录下的/conf下面。
①在#gzip
on;
后面加入下面配置:
upstreambackend{
serverlocalhost:
8080;
8088;
ip_hash;
}
其中serverlocalhost:
8080为第一个Tomcat的启动地址,serverlocalhost:
8088为第二个Tomcat的启动地址,ip_hash用于做session同步。
②修改第一个server{}配置中的listen
80;
改为新的端口号,因为我的本机80端口被IIS占用,因此将此处改为listen800;
。
并将
location/{
root
html;
index
index.htmlindex.htm;
改为:
index
proxy_pass
//backend;
proxy_redirect
off;
proxy_set_header
Host$host;
X-Real-IP$remote_addr;
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
proxy_read_timeout
proxy_buffer_size
4k;
proxy_buffers
432k;
proxy_busy_buffers_size
64k;
proxy_temp_file_write_size
其中proxy_pass参数和upstreambackend{}对应。
经过上面这些步骤,负载均衡配置就完成,下面前分别启动两台tomcat,然后双击nginx根目录下的nginx.exe文件或者用startnginx启动nginx,打开浏览器,输入地址:
http:
//localhost:
800便可看到下面画面:
这说明已经成功跳转到Tomcat上面。
下面以来电秀具体项目为例,输入地址:
800/ldxwebpersonal/personal/index/index.action