2016-11-18 1 views
0

Nginxは出力応答をgzipできません。 私は、簡単なカールコマンドを使用するだけでなく、chrome開発ツールを使用して確認しました。クライアント(ブラウザ)はHTTP要求をしながら "Accept-Encoding:gzip、deflate"を送信しています。ここでNginxが応答をgzipできません

はnginx.confファイル

worker_processes 2; 

events { 
    worker_connections 1024; 
} 


http { 
    include  mime.types; 
    sendfile  on; 
    keepalive_timeout 65; 

    gzip on; 
    gzip_vary on; 
    gzip_comp_level 5; 
    gzip_types text/html application/x-javascript text/css application/javascript text/javascript text/plain text/xml application/json application/vnd.ms-fontobject application/x-font-opentype application/x-font-truetype application/x-font-ttf application/xml font/eot font/opentype font/otf image/svg+xml image/vnd.microsoft.icon; 
    gzip_static on; 

    server { 
     listen 8080; 

     server_name localhost; 

     location/{ 
      root /home/ubuntu/project1/src; 
      index app.html; 
     } 
    } 


    server { 
     listen 8081; 

     server_name localhost; 

     location/{ 
      root /home/ubuntu/project2/src; 
      index app.html; 
     } 
    } 
} 

とのmime.typesの両方コマンド戻り

curl http://myserver/templates.js --silent --write-out "%{size_download}\n" --output /dev/null 

curl http://myserver/templates.js --silent -H "Accept-Encoding: gzip,deflate" -H “Accept: text/javascript” --write-out "%{size_download}\n" --output /dev/null 

カールコマンド同じバイト数(この中に17414を

types { 
    text/html        html htm shtml; 
    text/css        css; 
    text/xml        xml rss; 
    image/gif        gif; 
    image/jpeg       jpeg jpg; 
    application/x-javascript    js; 
    text/plain       txt; 
    text/x-component      htc; 
    text/mathml       mml; 
    image/png        png; 
    image/x-icon       ico; 
    image/x-jng       jng; 
    image/vnd.wap.wbmp     wbmp; 
    application/java-archive    jar war ear; 
    application/mac-binhex40    hqx; 
    application/pdf      pdf; 
    application/x-cocoa     cco; 
    application/x-java-archive-diff  jardiff; 
    application/x-java-jnlp-file   jnlp; 
    application/x-makeself    run; 
    application/x-perl     pl pm; 
    application/x-pilot     prc pdb; 
    application/x-rar-compressed   rar; 
    application/x-redhat-package-manager rpm; 
    application/x-sea      sea; 
    application/x-shockwave-flash   swf; 
    application/x-stuffit     sit; 
    application/x-tcl      tcl tk; 
    application/x-x509-ca-cert   der pem crt; 
    application/x-xpinstall    xpi; 
    application/zip      zip; 
    application/octet-stream    deb; 
    application/octet-stream    bin exe dll; 
    application/octet-stream    dmg; 
    application/octet-stream    eot; 
    application/octet-stream    iso img; 
    application/octet-stream    msi msp msm; 
    audio/mpeg       mp3; 
    audio/x-realaudio      ra; 
    video/mpeg       mpeg mpg; 
    video/quicktime      mov; 
    video/x-flv       flv; 
    video/x-msvideo      avi; 
    video/x-ms-wmv      wmv; 
    video/x-ms-asf      asx asf; 
    video/x-mng       mng; 
} 

ファイルであります場合)。 コンテンツを共有できない可能性がありますtemplate.js

+0

ショーカールであると私はあなた 'mime.types'は'テキスト/ javascript'が含まれていない問題の説明 –

+0

ファイルまたは'.js'。 'curl -v ....'レスポンスを表示する –

+0

に 'curl'コマンドが含まれている@AlexeyTen –

答えて

0

他にもいくつかの属性を追加しようとしました。

gzip_min_length 1000;

本当に奇妙な行動:私はnginx.confファイルに次を追加したとき、それは私のために働きました!ドキュメントによると、そのデフォルト値は20

http://nginx.org/en/docs/http/ngx_http_gzip_module.html

関連する問題