In case you don’t have an Nginx cluster or you are not powered in a cloud base infrastructure then recompiling the webserver may be a tricky job. If you are in one of the described situation you can setup all instances one by one having a stable platform.
Even so of course you can recompile the webserver without downtime.
- Create backups for all nginx files.
"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"
- Download all sources and dependencies for nginx
#You can check previous configuration parameters by nginx -V #Download all needed sources wget http://nginx.org/download/nginx-1.6.3.tar.gz wget https://github.com/pagespeed/ngx_pagespeed/archive/v220.127.116.11-beta.tar.gz wget https://github.com/openresty/headers-more-nginx-module/archive/v0.28.tar.gz nginx-headers.tar.gz wget https://dl.google.com/dl/page-speed/psol/18.104.22.168.tar.gz #Extract them tar -zxvf file.tar.gz
- Configure the compilation with custom parameters. You can even specify an other binary location for the new compiled software. In this way all the installed software will sill exist in the original files. In my case I decided to overwrite the existing binary of nginx.
./configure --add-module=/home/ec2-user/headers-more-nginx-module-0.28 --add-module=/home/ec2-user/ngx_pagespeed-22.214.171.124-beta --with-http_ssl_module
- Compile and install
sudo make sudo make test #run: "make install clean" This will install the new binary in place of the old one and makes a backup of the old one. sudo make install
- Sometimes this step is a little bit risky because some files may be opened and could not be overwritten. In my case everything worked fine. Even if the service was running in this time, the binary was already replaced.
- If you decided to go on a safer way and installed the binary in other place now all you have to change is defining your daemon to use this binary instead of old one, test the nginx configuration and restart the service.
A much more complex aprouch may be found here