4

I have a cluster of 8 independent web servers, each of them running nginx. They are all hosting the same websites and are being synced with rsync.

Also, each server has 8 different IP addresses attached to it.

My hosted websites are being directed to different IP's according to some business logic.

Is there some way i can sync the configuration file between all server, but change only the IP's on each one?

For example, have a nginx.conf on each server with:

@IP1 = '1.1.1.1';
@IP2 = '2.2.2.2';

include 'sites.conf';

and then sync the sites.conf and let it be something like:

server {
  listen @IP1:80;
  ... //more configurations here
}

Is it possible to do something like that?

5
  • 1
    As far as I know it is not possible with nginx, but you need to utilize a configuration management system like Puppet to control that.
    – pkhamre
    Feb 7, 2013 at 10:58
  • 3
    Puppet! Once you go puppet, you never look back! :)
    – Danie
    Feb 7, 2013 at 11:15
  • Does puppet support FreeBSD? i could'nt find any record of it in their site
    – shaharmor
    Feb 7, 2013 at 12:49
  • Rather than try to sync the same config, wouln't it be easier to use m4 or similar to generate the config from templates?
    – symcbean
    Feb 7, 2013 at 13:36
  • 1
    You can use Salt (saltstack.org) instead of Puppet. Puppet is implemented in Ruby, Salt is implemented in Python.
    – Ben.
    Feb 8, 2013 at 14:46

1 Answer 1

1

As others have noted, nginx doesn't support that.

On possibility might be to make use of separate config files for each of the individual hosts and have the nginx startup script reference that config file directly.

Method 1: multiple config files

/etc/init.d/nginx would do something like:

MyIP=`# some code to get my ip address or local ID`
nginx -c $PATH_TO_NGINX/${MyIP}.conf

In this manner, you are rsync'ing out the same files out to everyone, but each server will only reference their own config file.

Method 2: dynamically update the config file on service start/restart

MyIP=`# some code to get my ip address or local ID`
updateconfig($MyIP,$TEMPLATECONFIG,$LOCALCONFIG) # Some function which will take a template config distributed out and replace the IP-PLACEHOLDERS with the box's actual IP address
nginx -c $PATH_TO_NGINX/$LOCALCONFIG

In this manner, you only manage one config file template which self-updates on a restart/reload.

If you don't need the additional complexity of Puppet/config management yet, this is a low-overhead way to go, and because the config is dynamic, still allows you to scale out without worrying about the box's ip address. But if your architecture changes, then config management will be very helpful.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .