Dovadi

None of us is as smart as all of us.

Global Include for Nginx With a Wildcard.

We use Nginx as our webserver and loadbalancer with several different rails applications and we’re very satisfied with it. I thought let’s share the way we set up de nginx config file, because so far I haven’t read it elsewere.

In the global config file of nginx we use includes with wildcards, for example:


    include /u/apps/*/current/config/nginx.conf;
    include /u/apps/*/config/nginx.conf;

So now we only have to take care of the individual settings of an rails application for configuring its virtual domain(s), rewrite rules and etcetera in its own ‘local’ nginx.conf file in the rails/config directory (which is of course under version control).

When you want to start a new application after deployment, first test the configuration settings of nginx as follows:


  cd /usr/local/nginx
  sudo ./sbin/nginx -t

If everything is ok, you get something like this:


2008/05/09 17:06:10 [info] 19177#0: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
2008/05/09 17:06:10 [info] 19177#0: the configuration file /usr/local/nginx/conf/nginx.conf was tested successfully

Restart Nginx (all the local config files will be included as well), start your application and you’re done.


  sudo /etc/init.d/nginx restart

Very practical!

(Credits to my collegue Matthijs Kadijk.)