Linux下配置nginx,負載IIS的頁面


最近研究了下Linux下的nginx結果貼一下:

反向代理概念:

一般訪問流程:a=>b,a訪問b服務器,

加n來做反向代理流程:a=>n=>b

負載均衡概率:a訪問B站點,B站點有3台服務器,加入負載均衡n,a就訪問n,n然后按照規程平均的轉發給B站點的3台服務器。

配置環境:

1.本機電腦win10 系統,安裝虛擬機,虛擬機運行Linux系統。

2.本機win10的IIS下面掛載3個站點Server1,Server2,Server3。

3.linux系統安裝nginx。

4.win10和linux網絡相互ping通。

5.配置代理和配置負載均衡。

 

win10電腦ip:10.0.0175,配置的 Server1端口:8060 、Server2端口:8061 、Server3端口:8062 

linux電腦ip:http://192.168.201.130/  nginx默認監聽端口:80

一.配置反向代碼    server {

        listen       80;
        server_name  localhost;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

         location / {
            root   html;
            index  index.html index.htm;
        }
    
#配置IIS服務器站點為代理 location
/Server1/ { proxy_pass http://10.0.0.175:8060/; proxy_set_header X-real-ip $remote_addr; proxy_set_header Host $http_host; } location /Server2/ { proxy_pass http://10.0.0.175:8061/; proxy_set_header X-real-ip $remote_addr; proxy_set_header Host $http_host; }


  #配置Linux本地文件的的代理,相當於nginx作為服務器

      location /Server6/ {
          root /home/zyp/nginx/;
          index Index.html;
      }

加上以上配置,在win10系統訪問:

1.http://192.168.201.130/Server1 就會加載到8060端口的IIS上。

2.http://192.168.201.130/Server2 就會加載到8061端口的IIS上。

 

二.配置負載均衡   #配置負載均衡的站點

  upstream serverName{ server 10.0.0.175:8060; server 10.0.0.175:8061; server 10.0.0.175:8062; } server { listen 80; server_name localhost; #charset koi8-r; #access_log logs/host.access.log main; # location / { # root html; # index index.html index.htm; #} 
  #配置根目錄下負載serverName為自己上門定義的 location
/ { proxy_pass http://serverName; proxy_set_header X-real-ip $remote_addr; proxy_set_header Host $http_host; } }

配置完成,在win10 系統內訪問http://192.168.201.130,就是負載到個個站點。

這里只做簡單的配置,詳細的配置說明及其他配置可以參考淘寶團隊出的電子書:

http://tengine.taobao.org/book/


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2026 CODEPRJ.COM