1.安装nginx
- 执行安装指令 apt-get install nginx
- 查看版本 nginx -v
- 启动nginx service nginx start
- 访问页面,输入服务器的ip,出现欢迎界面
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关于负载均衡的配置
- 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
- 出现报错,把/etc/nginx/sites-enabled/default中的内容都注释掉,再重启
- 访问http://IP/test.jsp
本文摘自 :https://www.cnblogs.com/