Gzip
小李世界
4年前
修改理由:
此投稿已在 4年前 合并。
内容修改:
Old | New | Differences |
---|---|---|
1 | # | |
1 | ## Nginx 虚拟主机配置 | |
2 | 2 | |
3 | 3 | 如果你把应用程序部署到执行 `Nginx` 的服务器,你可以使用下面的配置内容来开始设置你的 `Web` 服务器。此配置内容最好根据你的服务器需求做一些自定义的修改。如果你需要托管你的服务器,可以考虑 [Laravel Forget](https://forge.laravel.com/) 等服务: |
4 | 4 | … | … |
36 | 36 | deny all; |
37 | 37 | } |
38 | 38 | } |
39 | ``` | |
40 | ||
41 | ||
42 | ## 开启 Gzip 压缩 | |
43 | ||
44 | 开启 Gzip 能让 Nginx 压缩一些文件,从而加载速度更快。 | |
45 | ||
46 | ``` | |
47 | sudo vim /etc/nginx/nginx.conf | |
48 | ``` | |
49 | ||
50 | 把 # 注释去掉。示例: | |
51 | ``` | |
52 | gzip on; | |
53 | gzip_comp_level 6; | |
54 | gzip_buffers 16 8k; | |
55 | gzip_http_version 1.1; | |
56 | gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript | |
57 | ``` | |
58 | ||
59 | 软重启 Nginx | |
60 | ``` | |
61 | sudo systemctl reload nginx | |
62 | ``` | |
63 | ||
64 | 测试是否生效: | |
65 | ``` | |
66 | curl -H "Accept-Encoding: gzip" -I http://www.example.com | |
67 | ``` | |
68 | ||
69 | 返回 `Content-Encoding: gzip` 即为成功。示例: | |
70 | ``` | |
71 | HTTP/1.1 200 OK | |
72 | Server: nginx | |
73 | Date: Wed, 26 Jun 2019 03:47:49 GMT | |
74 | Content-Type: text/html; charset=UTF-8 | |
75 | Connection: keep-alive | |
76 | Content-Encoding: gzip | |
39 | 77 | ``` |