Since I am hosting this blog in a very small linux box using Nginx as a web server I want to write the basic configuration so I have a reference to come back in the feature if I need to set this up again. Here is a guide to install Nginx. In a Debian-like linux OS Nginx sites configurations are loaded from the sites-enabled
directory but as a best practice I alway create the config file in the sites-available
and create a symlink.
This is the most basic configuration to server the site and have a custom 404 page:
server {
root /path/to/your/static/content;
index index.html;
server_name example.com www.example.com;
error_page 404 /404;
location / {
try_files $uri $uri/ $uri.html =404;
}
}
Since I want to optimize the configuration to cache some files like .css
and .js
I'll add some directives.
location ~* .(jpg|jpeg|png|gif|ico|css|js)$ {
expires 1d;
}
Since this is a static site, I'm pretty sure I won't have backend errors... well there is no backend code so, Im just going to log critical errors just for the lols.
error_log /var/log/nginx/error.log crit;
Also I'm using Analytics so I don't really care about the access logs, besides I don't want to use HD space with something I won't be using.
access_log off;
And finally I want to gzip
the content so:
gzip on;
gzip_min_length 10240;
gzip_comp_level 1;
gzip_vary on;
gzip_disable msie6;
gzip_proxied expired no-cache no-store private auth;
gzip_types
text/css
text/javascript
text/xml
text/plain
text/x-component
application/javascript
application/x-javascript
application/json
application/xml
application/rss+xml
application/atom+xml
font/truetype
font/opentype
application/vnd.ms-fontobject
image/svg+xml;
And some useful links for reference: