This note contains some of the configuration rules I use on my web server at home. The web server servers content of three different websites.

Note. If you are using OSX and brew, the location of Nginx configuration file is /usr/local/etc/nginx/nginx.conf.

Locations

Locations are a way to link a URL to a specific file in your filesystem.

Multiple locations can be set per server and Nginx will use the rule with the longest match.

Consider the following:

server {
      listen       80;
      server_name  spmbook.com;

      location / {
          root   html/spmbook;
          index  index.html index.htm;
      }

      location /course {
          alias  html/spm;
          index  index.html index.htm;
      }
}

tells nginx to serve all content of spmbook.com from the directory html/spmbook, with the exception of any URL containing /course, which will look for content in the html/spm directory.

Thus, for instance, http://spmbook.com/2014/index.html serves the file html/spmbook/2014/index.html, while http://spmbook.com/course/2014/index.html serves the file html/spm/2014/index.html.

Using multiple locations is useful, for instance, if you publish different websites under the same domain.

In my case, for instance, the html sources of spmbook.com and spmbook.com/course/2014 live in two different Jekyll repositories. Using different locations I can publish one independently from the other, while presenting them as belonging to the same domain.