Today I learned how to self-host gh-pages-esque project pages in an easy way using an nginx alias.

I have my main domain: which lives in /var/www/

I wanted to be able to cd into that directory, clone any new repos, and if there is a gh-pages branch, serve it with the url as

Normally, this URL structure doesn’t play nicely with jekyll sites, as jekyll compiles the site to the _site/ folder by default. The index.html file in /var/www/ is the yaml-filled jekyll-ready index file, not the compiled file with all of my posts listed out.

Essentially, I wanted to set the document root of to /var/www/

Here’s how I accomplished this task with an nginx alias:

server {
    listen 80;
    root /var/www/;
    index index.html;

    location /project-name/ {
	    alias /var/www/;

In a later post, I’d like to explore the possibility of doing this automatically, perhaps with a try_files directive.

Edit this Post