Blog by Daniel Hauck. Sysadmin, Developer, Blogger.

Oh man, this is hard, we are at part 4 and haven’t seen anything. This sucks. Let’s change it!

In this tutorial I will show you, how to install nginx and add virtual hosts, of course provisioned 😉

Install nginx

Create the role:

The first and obvious task is to get the latest version of nginx. And this we do again by adding a ppa in main.yml.

When you add a ppa, always remember to use an update_cache=yes, otherwise you will probably install the older version or your package won’t be available at all.

Next, we need to prepare the nginx.conf file for the vagrant machine. To make our all lifes easier, it’s a good idea to run nginx as the vagrant user, for the same reason we did if, with php-fpm. Of course we could just edit it. Or we could use lineinfile again as in the first tutorial.

So just replace user www-data with user vagrant. Easy ha?

After replacing the use, we should really take care of our virtual hosts now. I don’t like the default site, so let’s rid of it also. We use the same technique here, as in the php-fpm role and just render the apps list from global_vars, so we are more flexible for customization later. First create the template in provisioning/roles/nginx/templates/ and call it server.j2:

Create your task in main.yml:

and don’t forget to get rid of the default site and use a handler for restarting nginx after all that action.

Of course you are a smart dude and noticed, that I used a variable, we haven’t used before. Right, the domain variable. Let’s add it to the group_vars/all file:

The last thing we need to do here, is to create a handler, as we used it above. Therefore create a file in provisioning/roles/nginx/handlers/main.yml, but of course you already know where to put it 😉

Bam! That’s it, as always, don’t forget to add nginx to your playbook…

and run it!

Check your results

Today is a special day, we will see if all our stuff worked until now 😉

I don’t want to let you wait here, so just create a file called index.php, right in you project directory and fill it with

Save it, and go right to your browser and type in your addressbar and hit enter.

If everything works fine your result should look like the following:

OK! that’s it for todays post. Tomorrow I will show you, how to install postgresql and how to create databases. Stay tuned and don’t forget to share and subscribe!

There are no comments.

Leave a Reply