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 am using nginx as a load balancer in front of my web server instances. I run 4 instances of the web server and spread the traffic equally across them using nginx. When I am deploying new version - I change the nginx.conf and mark first 2 of the 4 servers down, then restart nginx. I update the server code and restart the first 2 servers. Then I edit nginx.conf to indicate that the first 2 servers are up and mark the other 2 down, again restart nginx. Then I update and restart other two instances. Again update the nginx.conf marking all servers up and final restart of nginx.

I have to do this process multiple times on some days. Manually performing the above steps every time turns out to be error prone.

Is there a programmatic access to nginx/nginx.conf so that I can automate this process?

[The only way I imagine right now is to write above steps in shell script]

share|improve this question
What you're doing seems very odd. Set fail_timeout to 5s on each of you backends, take two of them down and NGINX will pick that up and redirect all traffic to the second two nodes. Update your code, wait 5 seconds (or whatever your timeout value) and NGINX will start using the first two servers, then take down the second two and repeat. NGINX plays very nicely with that sort of setup – Smudge Dec 5 '11 at 11:18
up vote 2 down vote accepted

No, nginx does not have a configuration API.

Although there are cases when you might need to manually mark servers as down, generally configuring proxy_next_upstream + fail_timeout will work.

share|improve this answer

There is now nginx-conf, an NPM module that provides programmatic access to nginx configurations.

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.