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.
12"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
1234567891011#You can check previous configuration parameters bynginx -V#Download all needed sourceswget http://nginx.org/download/nginx-1.6.3.tar.gzwget https://github.com/pagespeed/ngx_pagespeed/archive/v22.214.171.124-beta.tar.gzwget https://github.com/openresty/headers-more-nginx-module/archive/v0.28.tar.gz nginx-headers.tar.gzwget https://dl.google.com/dl/page-speed/psol/126.96.36.199.tar.gz#Extract themtar -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.
1./configure --add-module=/home/ec2-user/headers-more-nginx-module-0.28 --add-module=/home/ec2-user/ngx_pagespeed-188.8.131.52-beta --with-http_ssl_module
- Compile and install
1234sudo makesudo 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