-
前期準備
- 安裝nginx(我前面的博客有說明)
- 安裝apache-tomcat-7.0.47.tar.gz
-
過程步驟
- 解壓apache-tomcat-7.0.47.tar.gz,tar -zxvf apache-tomcat-7.0.47.tar.gz,
- 重命名,mv apache-tomcat-7.0.47 apache-tomcat-sina
- 複製apache-tomcat-sina,命令:cp -r apache-tomcat-sina apache-tomcat-sina2
- 複製apache-tomcat-sina,命令:cp -r apache-tomcat-sina apache-tomcat-sohu
- 修改apache-tomcat-sina/webapps/ROOT/index.jsp文件,將後面加上-sina,如下圖:
- 同理,也修改apache-tomcat-sina2/webapps/ROOT/index.jsp文件,後面加上-sina2
- 也修改apache-tomcat-sohu/webapps/ROOT/index.jsp文件,後面加上-sohu
- 修改apache-tomcat-sohu/conf/server.xml配置文件,修改相對應的端口,將8005改爲8006,將8080改爲8081,將8009改爲8010
- 修改apache-tomcat-sina/conf/server.xml配置文件,修改相對應的端口,將8005改爲8007,將8080改爲8082,將8009改爲8011
- 啓動tomcat,通過瀏覽器訪問http://ip:8080,http://ip:8081,http://ip:8082
- 修改nginx.conf配置文件,如下:
upstream sina{ server 192.168.1.107:8080; server 192.168.1.107:8082 weight=2; } server { listen 80; server_name www.sina.com.cn; location / { proxy_pass http://sina; index index.html index.htm; } error_page 500 502 503 504 /50x.html; location = /50x.html { root html; } } upstream sohu{ server 192.168.1.107:8081; } server { listen 80; server_name www.sohu.com; location / { proxy_pass http://sohu; index index.html index.htm; } error_page 500 502 503 504 /50x.html; location = /50x.html { root html; } }
-
修改windows系統中的host文件,該文件在C:\Windows\System32\drivers\etc該路徑下,如下:
192.168.1.107 www.sina.com.cn 192.168.1.107 www.sohu.com
你在瀏覽器上訪問www.sina.com.cn,請求就回到192.168.1.107服務器地址上了,nginx就會根據域名重新找服務器
nginx反向代理和負載均衡搭建與測試
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.