Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
468 views
in Technique[技术] by (71.8m points)

vue配置gzip压缩,nginx也开启gzip,但是nginx中gzip_static不能与try_files共存是什么问题?

nginx中配置如下
location / {

#root   html;
root /usr/local/nginx/html;
index  index.html index.htm;
try_files $uri $uri/ /index.html; 
gzip_static on;

}

访问页面打开时空白页,调试查看index中的dist/build.js并没有正确的加载。

于是将try_files $uri $uri/ /index.html; 注释掉,页面时可以访问,.gz文件也能解压。但是注释掉后刷新带路径及参数的网址自然不能访问。

又将gzip_static on;注释掉,try_files $uri $uri/ /index.html; 取消注释。页面也能正确访问,但是不支持gz解压。

请问这种问题应该怎么解决?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

两个办法:

  1. 不用 try_files 用 if + rewrite
  2. 配置 gzip_static always + gunzip on;,给 .gz 文件创建一个空的未压缩文件。例如在 build.js.gz 同目录创建一个空的 build.js

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

56.6k users

...