📒
notebook
  • Notebook
  • DevOps
    • Git
      • 常见 Git 操作
      • 使用 SSH 连接 Git 远程仓库
      • 使用 GPG Keys 签名 Git 提交
      • Git on macOS
    • Docker
      • macOS 安装配置 Docker
      • CentOS7 安装配置 Docker CE
  • Linux
    • CentOS
      • CentOS7 安装配置 vsftpd
      • CentOS7 设置虚拟内存
      • CentOS7 使用 acme.sh 自动申请免费 SSL 证书
      • CentOS7 修改 SSH 端口号
      • CentOS7 主机初始设置
      • 阿里云 CentOS 主机常见设置
      • CentOS7 安装配置 SS
    • nginx
      • nginx 配置 301 永久重定向
      • nginx 使用 SSL证书配置 HTTPS
      • CentOS7 安装配置 nginx
      • nginx 配置 gzip 压缩
      • nginx 代理静态网页
  • Server
    • Ghost
      • macOS 安装配置 Ghost
      • CentOS7 安装配置 Ghost
    • npm & Yarn
      • Yarn 常用命令
      • CentOS7 安装卸载升级 Yarn
      • npm & Yarn 常见错误处理
      • macOS 安装卸载升级 Yarn
    • Node.js
      • Awesome Node.js
      • CentOS7 安装卸载升级 Node.js
      • macOS 安装卸载升级 Node.js
  • Web
    • Ionic
      • 创建 Ionic & Angular 项目
      • 使用 Ionic & Cordova 构建 Android 应用
      • macOS 搭建 Ionic & Cordova 开发环境
    • CSS
      • CSS 排版技巧
      • Awesome CSS
      • CSS 三栏自适应布局
    • Angular
      • Awesome Angular
      • 创建 Angular 项目
    • HTML
      • HTML head 常用标签
      • HTML 常用 DTD 声明
      • 常用网页语义结构
    • Web 技术标准
    • JavaScript
      • Awesome JavaScript
      • JavaScript 的 eval() 函数详解
  • Mobile
    • H5
      • iOS Safari Web App 配置
  • Development Environment
    • Development Utilities
      • Awesome Windows
      • macOS 安装配置 Homebrew
      • Awesome macOS
      • macOS 安装配置 iTerm2
    • FEED
      • 常用 Gulp 插件
  • Network
    • 常见公共 DNS
  • Technology Stacks for Web Front-End Development
Powered by GitBook
On this page
  • gzip 通用配置
  • 主机独立配置
  • 参考文献

Was this helpful?

  1. Linux
  2. nginx

nginx 配置 gzip 压缩

gzip 通用配置

创建一个用于保存 nginx 通用配置的目录:

sudo mkdir /etc/nginx/conf

新建 gzip 通用配置文件:

sudo vim /etc/nginx/conf/gzip.conf

插入配置:

### gzip.conf

# on | off
gzip on;

# buffers size
gzip_buffers 32 4k;

# compression level (1 - 9)
gzip_comp_level 1;

# disables on IE6 (matching "User-Agent" request header)
gzip_disable "MSIE [1-6]\.";

# minimum length of a response ("Content-Length" response header)
gzip_min_length 1k;

# minimum HTTP version
gzip_http_version 1.1;

# enables compression for all proxied requests
gzip_proxied any;

# inserting the “Vary: Accept-Encoding” response header
gzip_vary on;

# enables compression for the specified MIME types
gzip_types text/plain text/html text/xml text/css text/javascript application/javascript application/x-javascript application/json image/svg+xml image/x-icon image/gif image/jpeg image/png;

保存退出。

主机独立配置

打开需要开启 gzip 的主机配置文件:

sudo vim /etc/nginx/conf.d/avincheng.com.conf

在 server 域里引入通用配置文件:

server {
  listen 80;
  server_name avincheng.com;
  root /home/wwwroot/avincheng.com;
  index index.html;
  ...

  # gzip configuration
  include /etc/nginx/conf/gzip.conf;
}

保存退出,重启 nginx 服务:

sudo systemctl restart nginx

参考文献

PreviousCentOS7 安装配置 nginxNextnginx 代理静态网页

Last updated 4 years ago

Was this helpful?

Module ngx_http_gzip_module