Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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 = '';
@IP2 = '';

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?

share|improve this question
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 '13 at 10:58
Puppet! Once you go puppet, you never look back! :) – Danie Feb 7 '13 at 11:15
Does puppet support FreeBSD? i could'nt find any record of it in their site – shaharmor Feb 7 '13 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 '13 at 13:36
You can use Salt ( instead of Puppet. Puppet is implemented in Ruby, Salt is implemented in Python. – Ben. Feb 8 '13 at 14:46
up vote 1 down vote accepted

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

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.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.