日韩黑丝制服一区视频播放|日韩欧美人妻丝袜视频在线观看|九九影院一级蜜桃|亚洲中文在线导航|青草草视频在线观看|婷婷五月色伊人网站|日本一区二区在线|国产AV一二三四区毛片|正在播放久草视频|亚洲色图精品一区

分享

Nginx的gzip壓縮

 JhouShuai 2015-01-08


cat /usr/local/nginx/conf/nginx.conf

user  www;
worker_processes  2;

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


events {
    use epoll;
    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;
    client_max_body_size 20m;

    ####默認(rèn)情況下,Nginx的gzip壓縮是關(guān)閉的
    #gzip  on;

    server {
        listen       80;
        server_name  localhost;
        root html;
index index.php index.html index.htm

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        #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$ {
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.php;
            fastcgi_param  SCRIPT_FILENAME  $document_root$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;
        #}
    }

    server {
      listen       80;
      server_name  hipigo.51.local;
      root   /home/www/hipigo.cn/1.5.1/public;
      index  index.html index.htm index.php;

      charset utf-8;
      location ~ ^/(images|javascript|js|css|flash|media|static)/  {      
        expires 30d; 
        log_not_found off;
      }
      
      # 設(shè)置不被防問(wèn)的目錄
      location ~ ^/(application|library|var)/ {
        deny all;
      }
      
      #將request指向index.php
      location / {
        
        if (-f $request_filename) {
          break;
        }
        if (-d $request_filename) {
          break;
        }
        rewrite ^(.+)$ /index.php last;
      }
      
     
      #引用PHP CGI
      location ~ .*\.(php|php5)?$ {
          fastcgi_pass   127.0.0.1:9000;
          include fastcgi_params;
          fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name; 
          fastcgi_read_timeout 600;
      }
    }

    server {
      listen       80;
      server_name  hipigo.53.local;
      root   /home/www/hipigo.cn/1.5.3/public;
      index  index.html index.htm index.php;

      charset utf-8;
      location ~ ^/(images|javascript|js|css|flash|media|static)/  {
        expires 30d;
        log_not_found off;
      }

      # 設(shè)置不被防問(wèn)的目錄
      location ~ ^/(application|library|var)/ {
        deny all;
      }

      #將request指向index.php
      location / {

        if (-f $request_filename) {
          break;
        }
        if (-d $request_filename) {
          break;
        }
        rewrite ^(.+)$ /index.php last;
      }


      #引用PHP CGI
      location ~ .*\.(php|php5)?$ {
          fastcgi_pass   127.0.0.1:9000;
          include fastcgi_params;
          fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
          fastcgi_read_timeout 600;
      }
    }

    server {
      listen       80;
      server_name  hipigo.5.local;
      root   /home/www/hipigo.cn/1.5/public;
      index  index.html index.htm index.php;

      charset utf-8;
      location ~ ^/(images|javascript|js|css|flash|media|static)/  {      
        expires 30d; 
        log_not_found off;
      }
      
      # 設(shè)置不被防問(wèn)的目錄
      location ~ ^/(application|library|var)/ {
        deny all;
      }
      
      #將request指向index.php
      location / {
        
        if (-f $request_filename) {
          break;
        }
        if (-d $request_filename) {
          break;
        }
        rewrite ^(.+)$ /index.php last;
      }
      
     
      #引用PHP CGI
      location ~ .*\.(php|php5)?$ {
          fastcgi_pass   127.0.0.1:9000;
          include fastcgi_params;
          fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name; 
          fastcgi_read_timeout 600;
      }
    }


    server {
      listen       80;
      server_name  dev.2bi.net;
      root   /home/www/2bi/wwwroot/;
      index  index.php index.htm index.html;

      charset utf-8;
     
     location /admin/ {
       if (-f $request_filename) {
          break;
        }
        if (-d $request_filename) {
          break;
        }
        rewrite ^(.+)$ /admin/index.php last;
      }
     
     # 設(shè)置不被防問(wèn)的目錄
     # location ~ ^/home/ {
     #   deny all;
     # }
     #零售官網(wǎng)首頁(yè)
     location /home/ {
       if (-f $request_filename) {
          break;
        }
        if (-d $request_filename) {
          break;
        }
        rewrite ^(.+)$ /home/index.php last;
      }

 
     location / {
        
        if (-f $request_filename) {
            break;
        }
        if (-d $request_filename) {
          break;
        }
        rewrite ^(.+)$ /index.php last;
      }
      
     
      #引用PHP CGI
      location ~ .*\.(php|php5)?$ {
          fastcgi_pass   127.0.0.1:9000;
          include fastcgi_params;
          fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name; 
          fastcgi_read_timeout 600;
      }
    }


   server {
      listen       80;
      server_name  pay.dev.hipigo.cn;
      root   /home/www/hipigo.cn/pay/wwwroot/;
      index  index.php index.htm index.html;

      charset utf-8;
      location / {

        if (-f $request_filename) {
          break;
        }
        if (-d $request_filename) {
          break;
        }
        rewrite ^(.+)$ /index.php last;
      }


      #引用PHP CGI
      location ~ .*\.(php|php5)?$ {
          fastcgi_pass   127.0.0.1:9000;
          include fastcgi_params;
          fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
          fastcgi_read_timeout 600;
      }
    }

    
   server {
      listen       80;
      server_name  dev.cmen.com;
      root   /home/www/cmen/wwwroot/;
      index  index.php index.htm index.html;

      charset utf-8;

     location /admin/ {
       if (-f $request_filename) {
          break;
        }
        if (-d $request_filename) {
          break;
        }
        rewrite ^(.+)$ /admin/index.php last;
      }

     # 設(shè)置不被防問(wèn)的目錄
     # location ~ ^/home/ {
     #   deny all;
     # }
     #官網(wǎng)首頁(yè)
     location /home/ {
       if (-f $request_filename) {
          break;
        }
        if (-d $request_filename) {
          break;
        }
        rewrite ^(.+)$ /home/index.php last;
      }


     location / {

        if (-f $request_filename) {
            break;
        }
        if (-d $request_filename) {
          break;
        }
        rewrite ^(.+)$ /index.php last;
      }

      #引用PHP CGI
      location ~ .*\.(php|php5)?$ {
          fastcgi_pass   127.0.0.1:9000;
          include fastcgi_params;
          fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
          fastcgi_read_timeout 600;
      }
    }





    server {
      listen       80;
      server_name  wx.dev.hipigo.cn;
      root   /home/www/hipigo.cn/2.0/trunck/wwwroot;
      index  index.php index.htm index.html;

      charset utf-8;
    
      location /biz {

        if (-f $request_filename) {
          break;
        }
        if (-d $request_filename) {
          break;
        }
        rewrite ^(.+)$ /biz/index.php last;
      }

      location /wapi {

        if (-f $request_filename) {
          break;
        }
        if (-d $request_filename) {
          break;
        }
        rewrite ^(.+)$ /wapi/index.php last;
      }
location / {
        if (-f $request_filename) {
expires  max;
          break;
        }
if (!-e $request_filename){
rewrite ^/(.*)$ /index.php last;
}
}     
     
#引用PHP CGI
location ~ .*\.(php|php5)?$ {
fastcgi_pass   127.0.0.1:9000;
include fastcgi_params;
fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name; 
fastcgi_read_timeout 600;
}
}

    server {
      listen       80;
      server_name  manage.dev.xrenwu.com;
      root   /home/www/it008.com.xrenwu/manage/public;
      index  index.php index.htm index.html;

      charset utf-8;
      location / {

        if (-f $request_filename) {
          break;
        }
        if (-d $request_filename) {
          break;
        }
        rewrite ^(.+)$ /index.php last;
      }


      #引用PHP CGI
      location ~ .*\.(php|php5)?$ {
          fastcgi_pass   127.0.0.1:9000;
          include fastcgi_params;
          fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
          fastcgi_read_timeout 600;
      }
   }

   server {
      listen       80;
      server_name  api.dev.xrenwu.com;
      root   /home/www/it008.com.xrenwu/service/public;
      index  index.php index.htm index.html;

      charset utf-8;
      location / {
        rewrite ^(.+)$ /index.php last;
      }


      #引用PHP CGI
      location ~ .*\.(php|php5)?$ {
          fastcgi_pass   127.0.0.1:9000;
          include fastcgi_params;
          fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
          fastcgi_read_timeout 600;
      }
   }

   server {
      listen       80;
      server_name  dev.xrenwu.com;
      root   /home/www/it008.com.xrenwu/website/public;
      index  index.php index.htm index.html;

      charset utf-8;
      location / {

        if (-f $request_filename) {
          break;
        }
        if (-d $request_filename) {
          break;
        }
        rewrite ^(.+)$ /index.php last;
      }


      #引用PHP CGI
      location ~ .*\.(php|php5)?$ {
          fastcgi_pass   127.0.0.1:9000;
          include fastcgi_params;
          fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
          fastcgi_read_timeout 600;
      }
   }
    server {
      listen       80;
      server_name  att.it008.com;
      root   /home/www/hipigo.cn/att;
      index  index.php index.htm index.html;

      charset utf-8;
      location / {
        
        if (-f $request_filename) {
          break;
        }
        if (-d $request_filename) {
          break;
        }
        rewrite ^(.+)$ /index.php last;
      }
      
     
      #引用PHP CGI
      location ~ .*\.(php|php5)?$ {
          fastcgi_pass   127.0.0.1:9000;
          include fastcgi_params;
          fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name; 
          fastcgi_read_timeout 600;
    }
   }
}

以下內(nèi)容來(lái)自:

默認(rèn)情況下,Nginx的gzip壓縮是關(guān)閉的, gzip壓縮功能就是可以讓你節(jié)省不少帶寬,但是會(huì)增加服務(wù)器CPU的開(kāi)銷(xiāo)哦,Nginx默認(rèn)只對(duì)text/html進(jìn)行壓縮 ,如果要對(duì)html之外的內(nèi)容進(jìn)行壓縮傳輸,我們需要手動(dòng)來(lái)調(diào)。

開(kāi)啟gzip的指令如下:

 代碼如下復(fù)制代碼

gzip on;
gzip_http_version 1.0;
gzip_disable "MSIE [1-6].";
gzip_types text/plain application/x-javascript text/css text/javascript;

關(guān)于gzip_types,如果你想讓圖片也開(kāi)啟gzip壓縮,那么用以下這段吧:

gzip_types text/plain application/x-javascript text/css text/javascript application/x-httpd-php image/jpeg image/gif image/png;

網(wǎng)站開(kāi)啟gzip壓縮,不僅能夠節(jié)省帶寬,也能夠快速響應(yīng)用戶的訪問(wèn),在nginx中,開(kāi)啟gzip壓縮的方法為:
gzip on;      (啟用 gzip 壓縮功能)

    gzip_proxied any;  (nginx 做前端代理時(shí)啟用該選項(xiàng),表示無(wú)論后端服務(wù)器的headers頭返回什么信息,都無(wú)條件啟用壓縮)

    gzip_min_length  1024; (最小壓縮的頁(yè)面,如果頁(yè)面過(guò)于小,可能會(huì)越壓越大,這里規(guī)定大于1K的頁(yè)面才啟用壓縮)

    gzip_buffers     4 8k; (設(shè)置系統(tǒng)獲取幾個(gè)單位的緩存用于存儲(chǔ)gzip的壓縮結(jié)果數(shù)據(jù)流)

    gzip_comp_level 3; (壓縮級(jí)別,1壓縮比最小處理速度最快,9壓縮比最大但處理最慢,同時(shí)也最消耗CPU,一般設(shè)置為3就可以了)

    gzip_types       text/plain text/css application/x-javascript application/javascript application/xml; (什么類(lèi)型的頁(yè)面或文檔啟用壓縮)


注意:

1. 其中的gzip_http_version的設(shè)置,它的默認(rèn)值是1.1,就是說(shuō)對(duì)HTTP/1.1協(xié)議的請(qǐng)求才會(huì)進(jìn)行g(shù)zip壓縮
如果我們使用了proxy_pass進(jìn)行反向代理,那么nginx和后端的upstream server之間是用HTTP/1.0協(xié)議通信的
This module makes it possible to transfer requests to another server.
It is an HTTP/1.0 proxy without the ability for keep-alive requests yet. (As a result, backend connections are created and destroyed on every request.) Nginx talks HTTP/1.1 to the browser and HTTP/1.0 to the backend server. As such it handles keep-alive to the browser.
如果我們使用nginx通過(guò)反向代理做Cache Server,而且前端的nginx沒(méi)有開(kāi)啟gzip
同時(shí),我們后端的nginx上沒(méi)有設(shè)置gzip_http_version為1.0,那么Cache的url將不會(huì)進(jìn)行g(shù)zip壓縮
 
2. gzip_disable的設(shè)置是禁用IE6的gzip壓縮,又是因?yàn)楸叩腎E6
IE6的某些版本對(duì)gzip的壓縮支持很不好,會(huì)造成頁(yè)面的假死,今天產(chǎn)品的同學(xué)就測(cè)試出了這個(gè)問(wèn)題
后來(lái)調(diào)試后,發(fā)現(xiàn)是對(duì)img進(jìn)行g(shù)zip后造成IE6的假死,把對(duì)img的gzip壓縮去掉后就正常了
為了確保其它的IE6版本不出問(wèn)題,所以就加上了gzip_disable的設(shè)置


    本站是提供個(gè)人知識(shí)管理的網(wǎng)絡(luò)存儲(chǔ)空間,所有內(nèi)容均由用戶發(fā)布,不代表本站觀點(diǎn)。請(qǐng)注意甄別內(nèi)容中的聯(lián)系方式、誘導(dǎo)購(gòu)買(mǎi)等信息,謹(jǐn)防詐騙。如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請(qǐng)點(diǎn)擊一鍵舉報(bào)。
    轉(zhuǎn)藏 分享 獻(xiàn)花(0

    0條評(píng)論

    發(fā)表

    請(qǐng)遵守用戶 評(píng)論公約

    類(lèi)似文章 更多