大网数据广告活动
服务器运维问答

nginx : enabling gzip compression based on hostname

· 52CE 我爱测

I have a single machine running nginx serving http traffic for multiple domains(using same Lua codebase). For some of the domains I would like to enable gzip compression. Is it possible to enable gzip compression for specific set…

问题原文

原帖链接 · simplfuzz · CC BY-SA 3.0

I have a single machine running nginx serving http traffic for multiple domains(using same Lua codebase). For some of the domains I would like to enable gzip compression. Is it possible to enable gzip compression for specific set of domains? How?

已采纳解答

原帖链接 · Drifter104 · CC BY-SA 3.0

Absolutely if you take a look at the documentation you can see that it is acceptable to place gzip in any of the following levels http, server, location, if in location and as the domain is defined at the server level using server_name we can place gzip along side it.

First check your nginx.conf file for gzip on; if it is present remove it.

You then need to create a conf file and define where you want to use gzip.

server {
  server_name www.myexample.com;
  listen 80;
  gzip off;
}

server {
  server_name www.myotherexample.com;
  listen 80;
  gzip on;
}

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2016-05-04)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 3.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。