|
|
@@ -1,33 +1,18 @@
|
|
|
server {
|
|
|
- listen 80;
|
|
|
- server_name localhost;
|
|
|
+ listen 80 default_server;
|
|
|
+ server_name _;
|
|
|
|
|
|
- # 开启gzip压缩
|
|
|
gzip on;
|
|
|
- gzip_min_length 1k;
|
|
|
- gzip_comp_level 9;
|
|
|
- gzip_types text/plain text/css text/javascript application/json application/javascript application/x-javascript application/xml;
|
|
|
- gzip_vary on;
|
|
|
- gzip_disable "MSIE [1-6]\.";
|
|
|
+ gzip_min_length 1k; # 设置允许压缩的页面最小字节数
|
|
|
+ gzip_buffers 4 16k; # 用来存储 gzip 的压缩结果
|
|
|
+ gzip_http_version 1.1; # 识别 HTTP 协议版本
|
|
|
+ gzip_comp_level 2; # 设置 gzip 的压缩比 1-9。1 压缩比最小但最快,而 9 相反
|
|
|
+ gzip_types text/plain application/x-javascript text/css application/xml application/javascript; # 指定压缩类型
|
|
|
+ gzip_proxied any; # 无论后端服务器的 headers 头返回什么信息,都无条件启用压缩
|
|
|
|
|
|
- # 根目录配置
|
|
|
- root /usr/share/nginx/html;
|
|
|
- index index.html;
|
|
|
-
|
|
|
- # 处理Vue路由(避免404)
|
|
|
- location / {
|
|
|
+ location / { ## 前端项目
|
|
|
+ root /usr/share/nginx/html/;
|
|
|
+ index index.html index.htm;
|
|
|
try_files $uri $uri/ /index.html;
|
|
|
}
|
|
|
-
|
|
|
- # 静态资源缓存
|
|
|
- location ~* \.(js|css|png|jpg|jpeg|gif|ico|svg)$ {
|
|
|
- expires 1y;
|
|
|
- add_header Cache-Control "public, immutable";
|
|
|
- }
|
|
|
-
|
|
|
- # 禁止访问隐藏文件
|
|
|
- location ~ /\. {
|
|
|
- deny all;
|
|
|
- }
|
|
|
}
|
|
|
-
|