Add Custom nginx Configuration under Aegir 2

Your case may vary, but I had the following situation;

Customer has a monitoring solution, Monitorix, which they want to be available under their aegir host. Sure you can add the lines to the ~aegir/config/server_master/nginx/vhosts.d/domain.com.conf, but every time the hostmaster site is verified, you will have to re-add the necessary config lines. What a pain in the ass.

A better way is to create a custom drush module, containing the correct hook.

Here’s my ~aegir/.drush/kit.drush.inc

<?php
# Adds additional config lines to nginx config for specified uri
function kit_provision_nginx_vhost_config($uri, $data) {
    if ($uri === "host.example.com") {
        $rval[] = "";
        $rval[] = "  # Enables Alias for MonitorIX";
        $rval[] = "  location ^~ /monitorix {";
        $rval[] = "    proxy_pass http://127.0.0.1:8080;";
        $rval[] = "    proxy_set_header Host \$http_host;";
        $rval[] = "  }";
        $rval[] = "";
        return $rval;
    }
}
?>

Don’t forget to chmod +x ~aegir/.drush/kit.drush.inc so that Drush will be able to run your module

A few gotchas;

  • Line 3: You must begin your function name with the same string that you started the drush file as.  In my case, I used kit. You can use something equally as cool.
  • Line 3: If you’re using Apache instead of nginx, you should alter the function name and replace nginx with apache.
  • Line 4: You should change host.example.com to your aegir host.

Now, when a site is verified, and it’s hostname is host.example.com, the module will return the array containing the necessary config lines, which is then added to the config files located in ~aegir/config/server_master/nginx/vhosts.d/

Leave a Reply

Your email address will not be published. Required fields are marked *