1.安裝nginx??
- 執(zhí)行安裝指令 ? apt-get install nginx
- 查看版本? ? ? nginx -v
- 啟動nginx? ?? service nginx start
- 訪問頁面,輸入服務器的ip,出現(xiàn)歡迎界面
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中創(chuàng)建test.jsp文件,并編輯
<%@ page contentType="text/html;charset=UTF-8" %> <% out.print("歡迎訪問 tomcat1"); %>
?
4.修改nginx關于負載均衡的配置
- vi /etc/nginx/nginx.conf?在include /etc/nginx/sites-enabled/*;的下面插入
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; } }
?
- 重啟service nginx restart
- 出現(xiàn)報錯,把/etc/nginx/sites-enabled/default中的內(nèi)容都注釋掉,再重啟
- 訪問http://IP/test.jsp
?
本文摘自 :https://www.cnblogs.com/