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]

  • 3
    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
    – user80776
    Dec 5, 2011 at 11:18

2 Answers 2


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.


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

You must log in to answer this question.

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