Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/448.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 在nginx下提供gzip js和css文件web应用程序_Javascript_Node.js_Angular_Nginx_Gzip - Fatal编程技术网

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

Javascript 在nginx下提供gzip js和css文件web应用程序,javascript,node.js,angular,nginx,gzip,Javascript,Node.js,Angular,Nginx,Gzip,我有一个使用Angular(Angular cli)构建的web应用程序 要构建我的应用程序,我正在运行ng build--configuration=production 我听说Gzip操作已从angular cli中从此进程中删除,因此使用特定的npm包“Gzip程序”: 我习惯于使用一个组合命令生成和压缩输出的文件: ng build--configuration=production&&&&gzip-src/main/webapp/dist--log 我的输出文件如下所示: scrip

我有一个使用AngularAngular cli)构建的web应用程序

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

我听说Gzip操作已从angular cli中从此进程中删除,因此使用特定的npm包“Gzip程序”:

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

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

我的输出文件如下所示:

  • scriptOne.js
  • scriptOne.js.gzip
  • scriptTwo.js
  • scriptTwo.js.gzip
  • myStyle.css
  • 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未找到的文件 似乎它看不到那些gzip文件,我的应用程序无法提供服务


建议?

您必须添加
gzip\u static on

gzip  on;
gzip_static on;
ngx_http_gzip_static_模块允许发送文件扩展名为“.gz”的预压缩文件,而不是常规文件