Adopting a lean web app server infrastructure based on nginx (part 3/3)

##Introduction In this post, we’ll create two types of static sites:

  • in a sub domain : e.g.
  • in a sub folder: e.g. ##Create a static site in a sub domain First let’s go to our DNS (in my case and add a new sub domain called ‘demosite1’:

Let’s create a config file for this sub domain site in /etc/nginx/sites-available:

When doing a change to a nginx config file, you need to do a reload:

And create a symbolic link towards the sites-enabled directory:

When you browse now to you will get a 404, because the /usr/share/nginx/demosite1 folder has no content yet. Therefor, create a dummy index.html file in that folder

with following content:

<!DOCTYPE html>
<title>Welcome to nginx!</title>
<h1>Welcome to demo site 1!</h1>

##Create a static site in a sub folder of a sub domain Now imagine, that we want also to have a dedicated site in a sub folder of our newly created sub domain (e.g.

That’s just a matter of updating /etc/nginx/sites-available/ with:

We did again a change to a nginx config file, so we need to do a reload:

Create similarly a dummy html file under /usr/share/nginx/sub1.

##Conclusion Pretty simple. Obviously this file based approach can be easily integrated in a software factory where we will typically generate the appropriate config files programmaticaly. In a later episode, well leave the safe path of static sites and jump on the web application bandwagon. Stay tuned.

comments powered by Disqus