nginx實現負載均衡
阿新 • • 發佈:2017-07-04
nginx實現負載均衡
1.修改nginx.conf配置文件,在http大括號中添加如下配置
upstream nginx { server 192.168.2.140:8080; server 192.168.2.136:8080; }
2.修改server的location中的配置
location / { proxy_pass #就是這一行,這裏的nginx就是上面upstream 後面的nginx,這是一個名稱,請保存兩個 #地方是一致的 auth_basic off; auth_basic_user_file /var/user; root html; index index.html index.htm; }
3.準備兩臺服務器地址分別為192.168.2.140和192.168.2.136,並安裝apache服務器,端口使用8080
4.分別修改apache webapps/ROOT中的index.jsp,修改為簡單的內容
<!-- tomcat1中的index.jsp --> <html> <h1>tomcat1</h1> </html> <!-- tomcat2中的index.jsp --> <html> <h1>tomcat2</h1> </html>
5.在瀏覽器訪問http://www.nginx1.com/即可看到配置後的結果,每一次刷新請求不同的apache服務
本文出自 “素顏” 博客,請務必保留此出處http://suyanzhu.blog.51cto.com/8050189/1944312
nginx實現負載均衡