代码之家  ›  专栏  ›  技术社区  ›  firasKoubaa

在nginx下提供gzip js和css文件web应用程序

  •  0
  • firasKoubaa  · 技术社区  · 6 年前

    我有一个用 ( 角型cli

    要构建我的应用程序,我正在运行 ng build --configuration=production

    “Gzipper” : https://www.npmjs.com/package/gzipper

    我习惯于使用一个组合命令生成和压缩输出的文件:

    ng build --configuration=production && && gzipper src/main/webapp/dist --log

    我的输出文件如下所示:

    • scriptOne.js.gzip
    • scriptTwo.js
    • scriptTwo.js.gzip
    • myStyle.css.gzip

    nginx.conf.file文件 : 我已经把这个配置:

    http {
        include mime.types;
        default_type  application/octet-stream;
        client_max_body_size 10M;
    
        sendfile        on;
        keepalive_timeout  65;
    
        more_clear_headers "Server";
    
        gzip  on;
        gzip_types text/plain text/css application/json application/javascript application/x-javascript text/javascript text/xml application/xml application/rss+xml application/atom+xml application/rdf+xml;
    
        server {
           ...
        }
    

    404找不到文件

    建议?

    1 回复  |  直到 6 年前
        1
  •  1
  •   Poul Kruijt    6 年前

    gzip_static on;

    gzip  on;
    gzip_static on;
    

    ngx_http_gzip_static_模块允许发送文件扩展名为.gz的预压缩文件,而不是常规文件。