一、在nginx默認的web目錄 nginx/html 目錄下, 創建兩個文件夾: web1, web2。 html
二、分別放如index.html文件,web1的內容爲 web 1, web2的內容爲web 2。nginx
三、在nginx的配置文件 /nginx/conf/nginx.conf 文件中,默認的server{ ... } 段下,加入以下內容:web
server { listen 81; server_name localhost; #access_log logs/host.access.log main; location / { root html/web1; index index.html index.htm; } } server { listen 82; server_name localhost; location / { root html/web2; index index.html index.htm; } } upstream proxy_svrs { server localhost:81 weight=10; server localhost:82 weight=10; } server { listen 90; server_name localhost; location / { proxy_pass http://proxy_svrs; } }
四、此時訪問 http://localhost:81 , 出現web1的內容; 訪問 http://localhost:82 , 出現web2的內容。 代表兩個網站已建好。服務器
五、此時屢次訪問 http://localhost:90 , 會交替出現web1和web2的內容, 代表已成功啓動反向代理+負載均衡。負載均衡
至此, 實現的在一臺nginx服務器上的測試工做。 實際工做中應分別部署在三臺服務器中。測試