X

Install The ngx_cache_purge Module In Nginx

Ngx_cache_purge is a module which will allow the fastcgi_cache, proxy, SCGI and uWSGI caches to have content purged from them. The caches allow precompiled code to be served as opposed to running a new version each time. This can greatly reduce the amount of processing power per page request.  This specific module allows that cached content to be purged when needed.  To compile this module from source if you have done a source build of Nginx like this Nginx Compile From Source On CentOS. Adding the module is pretty straightforward. You can read more about the module here

First get the ngx_cache_purge package

wget -O /usr/src/ngx_cache_purge-2.3.tar.gz  http://labs.frickle.com/files/ngx_cache_purge-2.3.tar.gz

Uncompress the package

tar xfvz ngx_cache_purge-2.3.tar.gz

cd to your Nginx build directory

cd /usr/src/nginx-1.11.13

Get the prior build configuration options

# nginx -V
 nginx version: nginx/1.11.13
 built by gcc 4.8.5 20150623 (Red Hat 4.8.5-11) (GCC)
 built with OpenSSL 1.0.1e-fips 11 Feb 2013
 TLS SNI support enabled
 configure arguments: --user=nginx --group=nginx --prefix=/etc/nginx --sbin-path=/usr/sbin/nginx --conf-path=/etc/nginx/nginx.conf --pid-path=/var/run/nginx.pid --lock-path=/var/run/nginx.lock --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --with-http_gzip_static_module --with-http_stub_status_module --with-http_ssl_module --with-pcre --with-file-aio --with-http_realip_module --without-http_scgi_module --without-http_uwsgi_module --with-http_realip_module

Copy all of the configure arguments and append –add-module=/path/to/ngx_cache_purge

./configure --user=nginx --group=nginx --prefix=/etc/nginx --sbin-path=/usr/sbin/nginx --conf-path=/etc/nginx/nginx.conf --pid-path=/var/run/nginx.pid --lock-path=/var/run/nginx.lock --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --with-http_gzip_static_module --with-http_stub_status_module --with-http_ssl_module --with-pcre --with-file-aio --with-http_realip_module --without-http_scgi_module --without-http_uwsgi_module --with-http_realip_module --add-module=/usr/src/ngx_cache_purge-2.3

Once configure has finished, You can go ahead perform  a make and install it

make

make install

Then restart nginx

/etc/init.d/nginx restart

Run the following to ensure the module is now loaded:

nginx -V 2>&1 | grep ngx_cache_purge -o

It should return ngx_cache_purge if it is.

That is all you need to do to add the module to a Nginx build.

LinuxAdmin.io
5 1 vote
Article Rating
LinuxAdmin.io:

View Comments (8)

  • (dummy here)
    I just get: -bash: ./configure: No such file or directory
    whenever I try that long list of commands. Any advise?

      • Me too, I followed the exact steps you told, but I get ./configure: No such file or directory. I did cd to nginx dir. Why don't yo make a video and upload in youtube?

        • Hello Mike,
          If there is no configure, then you are not in the right directory. Could you please provide a listing inside of the nginx directory?

  • Is it possible to use the module in an already installed nginx without having to compile the current one?

    • Hello Jef,
      If you already have the module installed (check nginx -V output) you certainly can use that.

  • Hello!
    I did everything according to the instructions. I execute a command: nginx -V 2> & 1 | grep ngx_cache_purge -o but I get nothing in return.
    Configure the arguments: --sbin-path = / usr / sbin --conf-path = / etc / nginx / nginx.conf --error-log-path = / var / log / nginx / error.log -pid-path = / var / run / nginx.pid - lock-path = / var / lock / nginx.lock --http-log-path = / var / log / nginx / access.log --http-client-body-temp - path = / var / lib / nginx / body --http-proxy-temp-path = / var / lib / nginx / proxy --http-fastcgi-temp-path = / var / lib / nginx / fastcgi --with - debug --with-http_stub_status_module --with-http_flv_module --with-http_ssl_module --with-http_dav_module --with-http_v2_module --add-module = / tmp / ngx_cache_purge-2.3 --add-module = / tmp / openssl-1.1 .1-pre9

    Do you have any idea why this is so?

Related Post