Recompile Nginx

  1. Create backups for all Nginx files.
  2. "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. Download all sources and dependencies for Nginx
  4. #You can check previous configuration parameters by 
    nginx -V
    #Download all needed sources
    wget nginx-headers.tar.gz
    #Extract them 
    tar -zxvf file.tar.gz
  5. Configure the compilation with custom parameters. You can even specify another binary location for the newly compiled software. In this way, all the installed software will sill exist in the original location. In my case, I decided to overwrite the existing binary of Nginx.
    “/usr/local/nginx/sbin/nginx -V”
  6. ./configure  --add-module=/home/ec2-user/headers-more-nginx-module-0.28 --add-module=/home/ec2-user/ngx_pagespeed- --with-http_ssl_module
  7. Compile and install
  8. 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
  9. 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.
  10. If you decided to go on a safer way and installed the binary in another place, now all you have to change is defining your daemon to use this binary instead of the old one, test the Nginx configuration and restart the service.

A much more complex approach may be found here