Nginx gzip_static_module配置不起作用

时间:2017-06-25 01:44:10

标签: nginx heroku gzip

我在Heroku中使用nginx,我想启用http_gzip_static_module 提供压缩文件。我手动压缩我的文件,所以我有例如

bundle.js
bunsle.js.gz

我无法完成这项工作。如果我启用 gzip 动态压缩工作。我对ngnix并不熟悉,我正在使用我在互联网上找到的用于Heroku的配置,或者我应该说我使用的是Heroku buildpack,表示它是受支持的。

现在只有压缩对我很重要。如果我知道什么不重要,我会消除额外的噪音。有什么我应该改变的吗?这是我的配置文件。

daemon off;
#Heroku dynos have at least 4 cores.
worker_processes <%= ENV['NGINX_WORKERS'] || 4 %>;

events {
    use epoll;
    accept_mutex on;
    multi_accept    on;
    worker_connections 1024;
}


error_log   logs/nginx/error.log;
error_log   logs/nginx/error_extreme.log emerg;
error_log   logs/nginx/error_debug.log debug;
error_log   logs/nginx/error_critical.log crit;

http {

    charset utf-8;
    include mime.types;

    # # - Add extra mime types
    types{
        application/x-httpd-php .html;
    }
    default_type  application/octet-stream;


    log_format l2met 'measure#nginx.service=$request_time request_id=$http_x_request_id';

    access_log logs/nginx/access.log l2met;

    # # - Basic Settings

    sendfile        on;
    tcp_nopush      on;
    tcp_nodelay     on;
    types_hash_max_size       2048;


        # # - Enable open file cache

    open_file_cache max=1000 inactive=20s;
    open_file_cache_valid   30s;
    open_file_cache_min_uses    2;
    open_file_cache_errors  on;


    # # - Configure buffer sizes

    client_body_buffer_size 16k;
    client_header_buffer_size   1k;


    # # - Responds with 413 http status ie. request entity too large error if this value exceeds


    client_max_body_size    8m;
    large_client_header_buffers 2 1k;

    # # - Configure Timeouts

    client_body_timeout 12;
    client_header_timeout   12;

    # # - Use a higher keepalive timeout to reduce the need for repeated handshake

    keepalive_timeout   300;

    # # - if the request is not completed within 10 seconds, then abort the connection and send the timeout errror

    send_timeout    10;


    # # - Hide nginx version information

    server_tokens   off;

  # # - Dynamic gzip compression
    gzip_static                on;
    #gzip                      off;
    gzip_http_version         1.0;
    gzip_disable              "msie6";
    gzip_vary                 on;
    #gzip_min_length           20;
    #gzip_buffers              4 16k;
    #gzip_comp_level           9;
    gzip_proxied              any;


    #Turn on gzip for all content types that should benefit from it.


    gzip_types  application/ecmascript;
    gzip_types  application/javascript;
    gzip_types  application/json;
    gzip_types  application/pdf;
    gzip_types  application/postscript ;
    gzip_types  application/x-javascript;
    gzip_types  image/svg+xml;
    gzip_types  text/css;
    gzip_types  text/csv;
    gzip_types  text/javascript ;
    gzip_types  text/plain;
    gzip_types  text/xml;
    gzip_types  text/html;

    map $http_upgrade $connection_upgrade {
        default upgrade;
        '' close;
     }
     upstream nodebeats {
        server unix:/tmp/nginx.socket fail_timeout=0;
        keepalive   32;
     }

     server {
        listen       <%= ENV['PORT'] %>;
        server_name  _;
        root    "/app/";

        location / {
             proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
             proxy_set_header Host $http_host;
             proxy_redirect off;
             proxy_http_version 1.1;
             proxy_set_header   Upgrade $http_upgrade;
             proxy_set_header   Connection "upgrade";
             proxy_pass http://nodebeats;
        }

        location /api {
                proxy_pass http://nodebeats;
                proxy_http_version 1.1;
                proxy_set_header Upgrade $http_upgrade;
                proxy_set_header Connection 'upgrade';
                proxy_set_header Host $host;
                proxy_cache_bypass $http_upgrade;
           }

        location /dist {
            alias   "/app/app-dist";
            # # - 1 month expiration time
            expires 1M;
            access_log      off;
            add_header      Pragma public;
            add_header      Cache-Control public;
            add_header      Vary Accept-Encoding;
        }

        location /offline {
            alias   "/app/public/offline";
            # # - 1 month expiration time
            expires 1M;
            access_log      off;
            add_header      Pragma public;
            add_header      Cache-Control public;
            add_header      Vary Accept-Encoding;
        }

        location /scripts {
            alias   "/app/node_modules";
            # # - 1 month expiration time
            expires 1M;
            access_log      off;
            add_header      Pragma public;
            add_header      Cache-Control public;
            add_header      Vary Accept-Encoding;
        }
        }

}

0 个答案:

没有答案