Nginx for Drupal using Ansible

pbuyle's picture


I'm planning to configure Nginx to serve a Drupal site. The server uses Ansible for provisioning, and I'm planning to use perusio's config. The logical way to do it would be to create a role based on perusio's config.

Has anyone been working on something similar?


Hi, i also use ansible. I

dr.admin's picture

Hi, i also use ansible.

I create config for install web servers Using it you can configure webserver or db server in different configurations (apache+mysql+php, nginx+apache+php+mysql, also may configure php-fpm). Now i don't use perusio config, but i want to use it in future.

You can see this config, may be it will be usefull for you.


attiks's picture

I started working on ansible for boa, see for discussion, partial code can be found at

I started working on an

pbuyle's picture

I started working on an ansible role, it currently does the following

  1. Checkout perusio's config using Git (to a configurable directory, and only if the directory is not already a Git checkout).
  2. Override parametrized files (app/drupal/drupal.conf, nginx.con, etc.) using templates. The templates are files from perusio's config with jinja2 variables and conditional blocks.
  3. Create sites configuration files, again using a template files.

Everything is controlled through role's variables. For instance, the PHP handling method (apache proxy, php-cgi or php-fpm) is a variable, and everything it the parametrized configuration files that depends on the PHP handling method use conditional element.

The role does not install Nginx, Drupal, etc. It only manage the Nginx configuration directory. This allow consumer of the role to keep control of NGinx installation (packages, repository, etc.).

The role seems to work, last thing I was struggling with was the actual installation of (a configuration compatible) NGinx. I had to make some feature optional, for instance usage of AIO, that I couldn't get to work.

Code published

pbuyle's picture

The role can now be found at, this is still a work in progress.

Thanks for this project. Tell

dr.admin's picture

Thanks for this project. Tell me, please, is this configuration for nginx as reverse proxy for apache or php-fpm?

pbuyle's picture

The configuration it parametrized to use either one of them. Bits of the configuration depend on the solution, so the nginx_drupal_php_handling variable is used as conditions in template. This flexibility is inherited from perusio's configuration.

ок, i think i will use your

dr.admin's picture

ок, i think i will use your project in my project.
My ansible configuration i use for complete software installaion on server and configure it.

LAMP stack

Chi's picture

I've made a LAMP stack for Drupal development using Ansible for provisioning. I think some of these roles can be useful in the Nginx project.

Thanks, I'm also aware of

pbuyle's picture

Thanks, I'm also aware of Vlad ( which provide a full LAMP based development stack.

The role I published at is only for configuration of nginx, not installation of a full stack. It does not even manage the installation of nginx itself.

That said, I've also been working on roles related to the configuration of a full stack Drupal environement (php-cli, drush, php-pear, php-composer). And I also borrow roles found on Ansible Galaxy (php-fpm, mysql, solr, memcache, etc.).

It would be awesome to list Ansible roles related to Drupal in a wiki page. The hard part would be maintaining this page.

FWIW. . . .

jpw1116's picture

A few of us are considering that same "hard part" within the scope of a new initiative. The idea is to focus conversations on a list of Drupal-specific DevOps options, including LAMP/LEMP tooling, to reference and act as a concise resource:

Please leave feedback there on whether this may help you—the effort just started and is in that phase now, pre-Austin. Thanks.