nginx入門(一)window下實現簡單的負載平衡,nginxwindow
:http://nginx.org/en/download.html
我下載的是當前最新版本 (nginx/Windows-1.11.10)
解壓運行nginx.exe 可以看到命令列視窗一閃而過,查看工作管理員,可以看到多出兩個nginx.exe的進程
進入解壓目錄的conf下
這個檔案就是nginx的設定檔了,這個是window版的,有些配置被注釋掉了
配置詳細可以看這篇部落格 http://www.cnblogs.com/sunxucool/p/3225818.html
輸入localhost可以看到nginx的預設頁面
現在來使用一個web工程實現負載平衡...
改設定檔
worker_processes 1;events { worker_connections 1024;}http { include mime.types; default_type application/octet-stream; sendfile on; keepalive_timeout 65;upstream wgf.com{ #重新導向的配置server localhost:8081; #負載平衡伺服器1server localhost:8082; #負載平衡伺服器2} server { listen 80; #監聽連接埠 server_name localhost; #監聽ip location / {#root html; #index index.html index.htm; proxy_pass http://wgf.com; #監聽到的地址重新導向到這個地址proxy_redirect default; }error_page 500 502 503 504 /50x.html; #錯誤頁匹配location = /50x.html { root html; } }}
這個實現的原理可以從配置中大概看出來 監聽到localhost:80請求重新導向到nginx的偽網站http://wgf.com,
然後nginx通過配置找到最終訪問的伺服器位址localhost:8081 和localhost:8082
這兩個是我本地的兩個web工程,訪問localhost會在這兩個服務中輪換。效果如下