大型架構.net平台篇(WEB層均衡負載nginx)

來源:互聯網
上載者:User

標籤:

第一部分 WEB層均衡負載
.net平台下,我目前部署過的均衡負載有兩種方式(iis7和Nginx),以下以Nginx為例講解web層的均衡負載.


簡介:Nginx 超越 Apache 的高效能和穩定性,使得國內使用 Nginx 作為 Web 服務器的網站也越來越多,其中包括新浪部落格、新浪播客、網易新聞等門戶網站頻道,六間房、56.com等,視頻分享網站,Discuz!官方論壇、水木社區等知名論壇,豆瓣、YUPOO相簿、海內SNS、迅雷線上等新興Web 2.0網站。

據說Nginx能承受3萬並發串連數,這一點沒有測試,總之Nginx是以高並發著名的。

 

Nginx 做前端的均衡負載也是相當不錯的選擇,而且和具體的語言無關,下面是Nginx 分發到IIS的方式

簡單流程:使用者訪問網站(伺服器C)->伺服器C(不需要IIS) Nginx分發請求到->A或B或都更多的伺服器(具體的IIS伺服器), 實現前端負載

 

 

配置非常簡單,方法如下:

1.下載Nginx windows版本,網上搜一下就行了.下載後解壓放在C伺服器(192.168.0.3)C:或D:目錄下,例如(c:/nginx)
2. 把asp.net網站複製到A伺服器(192.168.0.1),B伺服器(192.168.0.2),並建立好相應的iis, 連接埠自已定, 例如(81)

確保A伺服器和B伺服器的頁面是完全一樣的,以及web.config需要配置machineKey一致,不然會報異常的。

<system.web>
    <machineKey validation="3DES"

validationKey="319B474B1D2B7A87C996B280450BB36506A95AEDF9B51211"

decryptionKey="280450BB36319B474C996B506A95AEDF9B51211B1D2B7A87"

decryption="3DES"/>


3. 配置C伺服器(前端負載轉寄伺服器)nginx的設定檔 nginx.conf
以下標紅的就是需要配置的.其中ip_hash很重要(可以保證每個訪客可以固定一個後端,保證session不會出問題)
#user  nobody;
worker_processes  1;

#error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;

#pid        logs/nginx.pid;


events {
    worker_connections  1024;
}


http {
    include       mime.types;
    default_type  application/octet-stream;

    #log_format  main  ‘$remote_addr - $remote_user [$time_local] "$request" ‘
    #                  ‘$status $body_bytes_sent "$http_referer" ‘
    #                  ‘"$http_user_agent" "$http_x_forwarded_for"‘;

    #access_log  logs/access.log  main;

    sendfile        on;
    #tcp_nopush     on;

    #keepalive_timeout  0;
    keepalive_timeout  65;

    #gzip  on;

upstream mytest.oa.com
{
ip_hash;
server 192.168.0.1:81;
server 192.168.0.2:81;
}
    server {
        listen       80;
        server_name  mytest.oa.com;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        location / {
            proxy_pass http://mytest.oa.com;
            proxy_redirect default;
        }

        #error_page  404              /404.html;

        # redirect server error pages to the static page /50x.html
        #
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }

        # proxy the PHP scripts to Apache listening on 127.0.0.1:80
        #
        #location ~ /.php$ {
        #    proxy_pass   http://127.0.0.1;
        #}

        # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
        #
        #location ~ /.php$ {
        #    root           html;
        #    fastcgi_pass   127.0.0.1:9000;
        #    fastcgi_index  index.php;
        #    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
        #    include        fastcgi_params;
        #}

        # deny access to .htaccess files, if Apache‘s document root
        # concurs with nginx‘s one
        #
        #location ~ //.ht {
        #    deny  all;
        #}
    }


    # another virtual host using mix of IP-, name-, and port-based configuration
    #
    #server {
    #    listen       8000;
    #    listen       somename:8080;
    #    server_name  somename  alias  another.alias;

    #    location / {
    #        root   html;
    #        index  index.html index.htm;
    #    }
    #}


    # HTTPS server
    #
    #server {
    #    listen       443;
    #    server_name  localhost;

    #    ssl                  on;
    #    ssl_certificate      cert.pem;
    #    ssl_certificate_key  cert.key;

    #    ssl_session_timeout  5m;

    #    ssl_protocols  SSLv2 SSLv3 TLSv1;
    #    ssl_ciphers  ALL:!ADH:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv2:+EXP;
    #    ssl_prefer_server_ciphers   on;

    #    location / {
    #        root   html;
    #        index  index.html index.htm;
    #    }
    #}

}

 

 

5. 配置完成後, 通過命令列進入ngnix目錄,運行ngnix.exe,即啟動ngnix。(請確保沒有其它iis或apache佔用80連接埠)

6.關閉ngnix命令為:ngnix -s stop.

大型架構.net平台篇(WEB層均衡負載nginx)

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.