5

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?

simplfuzz
  • 249
  • 4
  • 9

2 Answers2

4

Yes, it is. You should have a server block for each host name, just use

gzip on;

or

gzip off;

Inside each server block. The documentation can be found here. The only snag is if you've used some kind of wildcard, or don't have a server block per domain.

eg

server {
  server_name www.example.com;
  listen 80;
  root /what/ever;
  gzip on;
}

server {
  server_name www.example2.com;
  listen 80;
  root /what/ever2;
  gzip off;
}

If this doesn't make sense post your nginx configuration file and your site file(s) and we can take a look.

Tim
  • 30,383
  • 6
  • 47
  • 77
4

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;
}
Drifter104
  • 3,693
  • 2
  • 22
  • 39