This is a blog post for posterity - I’m sure I’ll forget how I did this and will go hunting again! and I must definitely be the last guy on the planet to be setting up nginx!
Nginx is pretty fast in itself. I use jekyll to power this site. So, when you’re reading this article, all the data is coming right off the hard disk - No databases, no queries, no lookups - simple fopen, read, stdout…
But you still want a bit more… A little bit of added juice from nginx. This is what I did - enabled http Caching and gZip compression.
And here’s how:
Open up your
nginx.conf file (on my box, it was at
/etc/nginx/nginx.conf) and head to the section under Gzip settings.
Uncomment the following chunk:
What we’re doing here is this:
- Turning on gzip compression - this must be on by default on nginx.
- Disabling compression for browsers that do not support compression
gzip_varyhelps set headers with
gzip_proxiedallows compression to happen even if the requests are coming in via a web proxy.
gzip_comp_level 6defines the level of compression between 1-9 (1 being lowest and 9 being highest)
- And other settings - the types of mimes to be pushed through the compression, the keep alive settings for the http 1.1 protocol, et al.
What really matters here is that you uncomment these lines.
Save the file and restart nginx.
To enable HTTP Caching, head out into
/etc/nginx/sites-enabled/<your-site-config-file> and make the following changes:
The first chunk disables expiry for html files. This will cause the text matter to be downloaded every time.
Another restart of nginx and you must notice a decent improvement in performance.
A quick way to check if your settings are in place is by using