歡迎您光臨本站 註冊首頁

nginx做負載均衡.net開發的網站出現棘手問題

←手機掃碼閱讀     火星人 @ 2014-03-04 , reply:0

nginx做負載均衡.net開發的網站出現棘手問題

我用兩台windows2003伺服器做網站,用nginx來做負載均衡,網站是用asp.net開發的

現在遇到一棘手的問題,做好了負載均衡后,發現一訪問網站,本來好好的頁面像散架一樣,一塊一塊的,像那種網速很慢的時候打開網頁一樣(不要質疑真的網速問題,還只是內部測試)

而如果在iis用靜態頁面或者一個簡單的asp頁面做網站,就很快

不知道是哪裡沒配置好?

我的nginx配置文件如下:

http {
    upstream new.xxx.com {
    server    10.0.0.2:8080;
    server    10.0.0.3:80;
    server    10.0.0.4:80;
}

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

    keepalive_timeout  120;
    tcp_nodelay on;

    #gzip  on;

    server {
        listen       80;
        server_name  new.xxx.com;


       #access_log  logs/host.access.log  main;

        location /nginxstatus {
            stub_status on;
     access_log off;
        }


location / {
   proxy_pass  http://new.xxx.com;
   proxy_set_header Host $host;
   proxy_set_header        X-Real-IP $remote_addr;
   proxy_set_header        X-Forwarded-For $proxy_add_x_forwarded_for;
  
}
        #error_page  404              /404.html;

        # redirect server error pages to the static page /50x.html
        #
   }
}

大家幫我參謀一下,謝謝了
《解決方案》

頂一下,希望有人出出主意!
《解決方案》

先測試下反向代理一台伺服器是否還有訪問慢的問題
《解決方案》

回復 2# davie5201314


    如果放一個簡單的測試頁面就很快,我放一個<%=now()%>的asp頁面,很快就出來
但是一把整個網站架上去就很多圖片都是叉叉
如果不用nginx做負載均衡,又一點問題沒有,不知道是什麼原因?
《解決方案》

在upstream new.xxx.com{}配置段中加入ip_hash指令看看情況
《解決方案》

回復 5# chenyx


    加了ip_hash;后只能看到IE下面載入網頁的進度條了,截止目前為止,還在載入!
《解決方案》

worker_processes  1;

#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;
    tcp_nodelay        on;
    keepalive_timeout  120;

    #buffer
    client_header_buffer_size    1k;
    large_client_header_buffers 4 4k;
    output_buffers        1 64k;
    postpone_output       1460;

    #gzip
    gzip                  on;
    gzip_min_length       1100;
    gzip_buffers          4 32k;
    gzip_types            text/plain;


   
upstream new.xxx.com {

    server    192.168.1.2:8080 weight=3;
    server    192.168.1.3:80;
    server    192.168.1.4:80;
        }


    server {
        listen       80;
        server_name  new.xxx.com;
        charset                gb2312;       

       access_log  logs/host.access.log  main;

        #location /nginxstatus {
        #    stub_status on;
        #    access_log off;
        #}
       
        #location ~* ^.+.(img|js|css|jpg|gif|png|html)$ {
        #access_log        off;
        #expires         30d;
        #}

        location / {
          proxy_pass                http://new.xxx.com;
          proxy_redirect        default;
          proxy_set_header        Host $host;
          proxy_set_header        X-Real-IP $remote_addr;
          proxy_set_header        X-Forwarded-For $proxy_add_x_forwarded_for;
          client_max_body_size        10m;
          client_body_buffer_size     128k;
          proxy_connect_timeout       90;
          proxy_send_timeout          90;
          proxy_read_timeout          90;
          proxy_buffer_size           32k;
          proxy_buffers               4 64k;
          proxy_busy_buffers_size     128k;
          proxy_temp_file_write_size         128k;

        }
        #error_page  404              /404.html;

        # redirect server error pages to the static page /50x.html
        #
   }
}

繼續修改,成這樣了,還是散的頁面,圖片顯示很少部分
《解決方案》

把upstream new.xxx.com 後面的new.xxx.com 改個別的名字,比如abc
proxy_pass                http://abc
再試試
《解決方案》

回復 8# chenyx


    改過,一樣,其它的沒什麼,應該就是css和圖片沒有轉發,不知道怎麼會出現這樣的問題

[火星人 ] nginx做負載均衡.net開發的網站出現棘手問題已經有891次圍觀

http://coctec.com/docs/service/show-post-5746.html