Configure Nginx for Jekyll / Octopress / pelican based static website

This post explain, how to configure Nginx web server for Static Website. At the current time, Jekyll,Octopress, pelican are very popular static site generator. Generally for static website we use html files.

Note: This post share the Nginx Configuration file settings for static website.

We worked on couple of website which were generated with Jekyll,Octopress and pelican.In this post we are sharing the Nginx configuration file for static website.

We have added some feature in this Nginx configuration file which will help your Nginx site to load quickly. These features are given below –

1. Enable compression
2. Enable Leverage Browsing

We believe you have already install Nginx on your system (Install Nginx on CentOS 7)

Given below is the Nginx Configuration file settings –
Replace example.com with your domain name.

server {

    ## Give Domain name
    server_name example.com www.example.com;

    ## Define custom path for Nginx site log
    access_log /var/log/nginx/example.com-access.log;
    error_log /var/log/nginx/example.com-error.log;

    ## Give absolute path of Web root where your website files/dir are saved
    root /usr/local/nginx/html/examplecom_octopress;

    ## Define the index file
    index index.html;
    autoindex off;

    ## Setting Compression
  
    gzip on;
    gzip_disable "msie6";
    gzip_min_length 1100;
    gzip_vary on;
    gzip_proxied any;
    gzip_comp_level 6;
    gzip_buffers 16 8k;
    gzip_http_version 1.1;
    gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript;

    ## Define 404 pages URL
    location / {
     try_files $uri $uri/ =404; 

   }

    # Disable favicon.ico logging
    location = /favicon.ico {
        log_not_found off;
        access_log off;
    }

    # Allow robots and disable logging
    location = /robots.txt {
        allow all;
        log_not_found off;
        access_log off;
    }


    # Disable static content logging and set cache time to max
    location ~* .(js|css|png|jpg|jpeg|gif|ico)$ {
        expires 365d;
        log_not_found off;
    }

    # Deny access to htaccess and htpasswd files
    location ~ /.ht {
        deny  all;
    }
}

After saving the file.Run the command nginx -t , to check if any error in configuration file

Restart the Nginx Service.

On CentOS 7 / RHEL 7

systemctl restart nginx

On CentOS 5,6 / RHEL 5,6

service nginx restart

On Debian / Ubuntu

sudo service nginx restart

OR

sudo /etc/init.d/nginx restart