Nginx gzip_静态_模块配置不工作

Nginx gzip_静态_模块配置不工作,nginx,heroku,gzip,Nginx,Heroku,Gzip,我正在和Heroku一起使用nginx,我想启用 提供压缩文件。例如,我手动压缩我的文件 bundle.js bunsle.js.gz 我做不到。如果我在上启用gzip,动态压缩就可以工作。我对ngnix不是很熟悉,我正在使用我在互联网上找到的配置来与Heroku一起使用,或者我应该说我正在使用的配置表明它是受支持的 现在只有压缩对我来说是重要的。如果我知道什么不重要,我会消除额外的噪音。有什么我应该改变的吗?这是我的配置文件 daemon off; #Heroku dynos have at

我正在和Heroku一起使用nginx,我想启用 提供压缩文件。例如,我手动压缩我的文件

bundle.js
bunsle.js.gz
我做不到。如果我在上启用gzip,动态压缩就可以工作。我对ngnix不是很熟悉,我正在使用我在互联网上找到的配置来与Heroku一起使用,或者我应该说我正在使用的配置表明它是受支持的

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

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;
        }
        }

}
守护进程关闭;
#Heroku dynos至少有4个磁芯。
工人的工作流程;
事件{
使用epoll;
接受上的互斥;
多重接受;
工人(1024);;
}
错误日志/nginx/error.log;
error\u log logs/nginx/error\u extreme.log emerg;
error\u log logs/nginx/error\u debug.log debug;
error\u log logs/nginx/error\u critical.log crit;
http{
字符集utf-8;
包括mime.types;
##-添加额外的mime类型
类型{
application/x-httpd-php.html;
}
默认_类型应用程序/八位字节流;
log_format l2met'measure#nginx.service=$request_time request_id=$http_x_request_id';
access_log logs/nginx/access.log l2met;
##-基本设置
发送文件到;
tcp_nopush on;
tcp_节点延迟开启;
类型\散列\最大\大小2048;
##-启用打开文件缓存
打开\u文件\u缓存最大值=1000非活动=20s;
打开\u文件\u缓存\u有效30秒;
打开\u文件\u缓存\u最小\u使用2;
打开上的\u文件\u缓存\u错误;
##-配置缓冲区大小
客户端\主体\缓冲区\大小16k;
客户端\头\缓冲区\大小1k;
##-以413 http状态响应,即如果此值超过,则请求实体太大错误
客户的最大尺寸为8米;
大客户机头缓冲区21K;
##-配置超时
客户端\主体\超时12;
客户端\头\超时12;
##-使用更高的keepalive超时来减少重复握手的需要
保持激活超时300;
##-如果请求未在10秒内完成,则中止连接并发送超时错误
发送超时10;
##-隐藏nginx版本信息
服务器_令牌关闭;
##-动态gzip压缩
gzip_静态开启;
#gzip关闭;
gzip_http_版本1.0;
gzip_禁用“msie6”;
gzip_随时间而变化;
#gzip_最小长度20;
#gzip_缓冲器4 16k;
#gzip_comp_9级;
gzip_代理任何;
#为所有应该受益于gzip的内容类型启用gzip。
gzip_类型应用程序/ecmascript;
gzip_类型应用程序/javascript;
gzip_类型应用程序/json;
gzip_类型应用程序/pdf;
gzip_类型应用程序/postscript;
gzip_类型应用程序/x-javascript;
gzip_类型image/svg+xml;
gzip_类型文本/css;
gzip_类型文本/csv;
gzip_类型text/javascript;
gzip_类型文本/纯文本;
gzip_类型text/xml;
gzip_类型text/html;
映射$http\u升级$connection\u升级{
默认升级;
""关闭,;
}
上游节羚{
服务器unix:/tmp/nginx.socket失败\u超时=0;
保持32;
}
服务器{
听
服务器名称;
root“/app/”;
地点/{
proxy\u set\u header X-Forwarded-For$proxy\u add\u X\u Forwarded\u For;
代理设置头主机$http\U主机;
代理_重定向关闭;
proxy_http_版本1.1;
代理设置头升级$http\U升级;
代理设置头连接“升级”;
代理通行证http://nodebeats;
}
地点/空气污染指数{
代理通行证http://nodebeats;
proxy_http_版本1.1;
代理设置头升级$http\U升级;
代理集头连接“升级”;
代理设置头主机$Host;
代理缓存绕过$http\u升级;
}
地点/地区{
别名“/app/app dist”;
##-1个月到期时间
1百万美元;
访问/注销;
添加标题Pragma public;
添加_头缓存控制公共;
添加_头,改变接受编码;
}
位置/脱机{
别名“/app/public/offline”;
##-1个月到期时间
1百万美元;
访问/注销;
添加标题Pragma public;
添加_头缓存控制公共;
添加_头,改变接受编码;
}
位置/脚本{
别名“/app/node_modules”;
##-1个月到期时间
1百万美元;
访问/注销;
添加标题Pragma public;
添加_头缓存控制公共;
添加_头,改变接受编码;
}
}
}

您希望nginx压缩输出流还是压缩文件本身?在您的示例中,如果您请求,它将在传输过程中被压缩(如果请求客户端告诉服务器,它可以通过设置请求头(如“accept encoding:gzip”)来接收和解码压缩响应)。在nginx中设置压缩不会导致将文件上载为bundle.js.gz。也许我理解错了?我使用的是webpack,在打包过程中我压缩了所有文件,所以我得到bundle.js和bundle.js.gz、vendor.js和vendor.js.gz。我希望nginx查找这些文件并将它们提供给浏览器,这样当客户端请求某些内容时就不会进行动态压缩,它只查找已经压缩的文件。我在这里发现了一些提示,可能是proxy_pass给我带来了麻烦,但我不知道舒尔如何解决这个问题。您希望nginx压缩输出流还是压缩文件本身?在你的例子中,如果