网址:http://www.softwareprojects.com/resources/programming/t-recompileupgrade-nginx-binary-with-no-down-time-1520.html

How to recompile nginx and replace current binary, with no down-time:

 
Follow the same generic steps as a regular install initially.
 
1. Download and untar the nginx source if you don't have it on your machine already.
 
2. Make a copy of your current nginx binary and conf. The installation usually does this automatically, but just to be safe. 
 
"cp /usr/local/nginx/sbin/nginx /usr/local/nginx/sbin/nginx_old"
"cp /usr/local/nginx/conf/nginx.conf /usr/local/nginx/conf/nginx.conf.old"
 
3. Run the "./configure" command. For example if you wanted to add SSL support to nginx, you would have a configure statement such as:
 
./configure --with-http_ssl_module --with-openssl=/path/to/openssl_src
 
If you have other options you need you can add those as well. To see what your current nginx has configured, run the binary with -V flag ie. 
 
"/usr/local/nginx/sbin/nginx -V"
 
4. run: "make install clean" This will install the new binary in place of the old one and makes a backup of the old one.
 
These steps are more specific to replacing a current install without down-time:
 
5. Send a USR2 signal to the current pid file, something like: 
 
"kill -USR2 `cat /usr/local/nginx/logs/nginx.pid`".
 
This causes nginx master process that was running to rename its pid and start the new binary. Both will run simultaneously.
 
6. To disable the old workers, send the old master process a WINCH signal. If your pid is '123' that would be something like: 
 
"kill -WINCH 123"
 
7. Now you can test the new nginx process to see if it's working. If it is, you can kill the old master process to allow the new one to take over. If the old master process had a PID of '123' you would do this:
 
"kill -QUIT 123"
 
If you find your new binary isn't working correctly, maybe due to a mistake during configuration, you can revert back to the old master process by doing the following. Assume your old master process has a PID of '123' and the new master process has a PID of '321':
 
"kill -HUP 123" - this will restart the workers under the old master process
"kill -QUIT 321" - shuts down the new master process workers
"kill -TERM 321" - shuts down the new master process
 
You can find some additional information about nginx upgrades and signals here:
http://wiki.codemongers.com/NginxCommandLine#utnbotf