1.安装nginx
2.安装三个tomcat,注意修改/conf/server.xml中的三处端口号
<Server port="9005" shutdown="SHUTDOWN"> <Listener className="org.apache.catalina.startup.VersionLoggerListener" /> <Connector port="9080" protocol="HTTP/1.1" connectionTimeout="20000" redirectPort="8443" /> <Connector port="9009" protocol="AJP/1.3" redirectPort="8443" />
3.在tomcat/webapp/ROOT中创建test.jsp文件,并编辑
<%@ page contentType="text/html;charset=UTF-8" %> <% out.print("欢迎访问 tomcat1"); %>
4.修改nginx关于负载均衡的配置
upstream tomcat_server { server 127.0.0.1:7080 weight=1; server 127.0.0.1:8080 weight=1; server 127.0.0.1:9080 weight=1; } server { listen 80 default_server; server_name localhost; location / { proxy_pass http://tomcat_server/; proxy_redirect default; proxy_set_header Host $http_host; proxy_set_header X-Forward-For $remote_addr; } error_page 500 502 503 504 /50x.html; location = /50x.html { root html; } }