1

I want create a task on my Capistrano deploy to put my public IP on geo module configuration of my NGINX server without restart NGINX, is it possible? Example, my /etc/nginx/nginx.conf:

geo $geo {
  default no;
  include /home/deploy_user/appname/shared/ip_list;
} 

The file /home/deploy_user/appname/shared/ip_list I will provide during deploy. I need this because my public IP can change many times.

Regards, João

joaorvmaia
  • 11
  • 2

1 Answers1

1

Since your configuration file is located in /etc/nginx I'm assuming your using some kind of Debian based flavor of Linux.

I'd basically backup and replace the ip_list at deploy time with something like this:

cd /home/deploy_user/appname/shared/ip_list
mv ip_list ip_list`date +"%Y%m%d%H%M%S"`
cp <path to new ip_list> ip_list

Then you can reload your configurations into Nginx without loosing any requests by issuing:

sudo service nginx reload or sudo /etc/init.d/nginx reload.

This will kill off any workers with the old config as they finish and start up all new workers with your new config. This way you won't loose any requests

Just make sure you can run your command with elevated privileges from Capistrano since this is necessary to reload/restart Nginx.

deRailed
  • 151
  • 3
  • Yes, I use Ubuntu. In my case I don't need backup IPs but it's interesting. Nice! It works! But, I still have one problem, my application restart when nginx reload, but I think it's not pertinent of this thread. Explaining my case, my application is a Rails App using Passenger, I think will be more interesting now change to Unicorn. thanks! – joaorvmaia Nov 08 '12 at 11:57
  • I guess you could take a look at [this gist](https://gist.github.com/1551881) which shows how to issue certain signals to Unicorn from Capistrano. Good luck. – deRailed Nov 08 '12 at 15:50
  • I will look, thks! – joaorvmaia Nov 08 '12 at 22:12