一、反向代理,多台机器
1.需求和目的:nginx代理两台服务器,这两台服务器使用tomcat模拟
浏览器访问http://localhost:9001/beijing/index.html,通过nginx,跳转到一个tomcat上(端口8080),浏览器上显示beijing
浏览器访问http://localhost:9001/shanghai/index.html,通过nginx,跳转到一个tomcat上(端口8081),浏览器上显示shanghai
2.准备两台tomcat:
a.已经安装好的tomcat,端口默认就是8080
b.再下载一个解压版的tomcat,修改端口为8081,是修改server.xml
修改下面两个:
<Server port="8015" shutdown="SHUTDOWN">
<Connector port="8081" protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="8443"
maxParameterCount="1000"
/>
c.两个tomcat准备两个index.html: 然后把两个tomcat分别启动起来。
3.nginx配置:
http {
include mime.types;
default_type application/octet-stream;
server {
listen 9001;
server_name localhost;
location ~ /beijing/ {
proxy_pass http://localhost:8080;
}
location ~ /shanghai/ {
proxy_pass http://localhost:8081;
}
}
}
解释:
4.测试访问:分别访问http://localhost:9001/beijing/index.html 和 http://localhost:9001/shanghai/index.html 页面上正确展示beijing、shanghai,测试OK
----
标签:beijing,http,tomcat,index,windows,nginx,使用,localhost From: https://www.cnblogs.com/tenWood/p/18054885