Muh*_*eed 6 gzip nginx brotli ngx-brotli
我想使用NGINX 启用GZIP和Brotli压缩.我必须在我的nginx.conf中为每个提供自己的MIME类型列表,如下所示:
gzip_types text/plain
text/css
...etc;
brotli_types text/plain
text/css
...etc;
Run Code Online (Sandbox Code Playgroud)
如何创建可由两个设置使用的单个MIME类型列表?
将两个列表设置为同步几乎是一项一次性任务,因为可以从压缩中受益的 MIME 类型数量大约在 20 个左右。
如果绝对需要从中心位置管理列表,我建议考虑开发一个 Ansible playbook 将 Nginx 配置推送到服务器。
Ansible playbook 中与推送相应配置相关的部分如下所示:
- name: "Set fact for compressible MIME types"
set_fact:
compressibles:
- "text/css"
- "application/javascript"
- "..."
- name: "copy {{ item }} conf.d config file"
template:
src: "{{ item }}.conf.j2"
dest: "/etc/nginx/conf.d/{{ item }}.conf"
with_items:
- brotli
- gzip
notify: reload nginx
Run Code Online (Sandbox Code Playgroud)
gzip.conf.j2:
gzip on;
gzip_types {{ compressibles|join(' ') }};
# whatever else you think is relevant for gzip configuration
# ...
Run Code Online (Sandbox Code Playgroud)
brotli.conf.j2
brotli on;
brotli_types {{ compressibles|join(' ') }};
# whatever else you think is relevant for brotli configuration
# ...
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
428 次 |
| 最近记录: |