nginx 1.0.0 with ngx_cache_purge for efficient reverse proxy

  • 2020-05-06 12:12:57
  • OfStack

Functionally, Nginx already has Squid's Web cache acceleration and the ability to clear the specified URL cache. In terms of performance, Nginx makes much better use of multi-core CPU than Squid. In addition, Nginx is much more powerful than Squid in terms of reverse proxy, load balancing, health check, back-end server failover, Rewrite rewrite, and ease of use. This allows an Nginx to be used as both a "load balancing server" and an "Web cache server". - by Zhang Yan

Download the latest version 1.3
of the 2011-05-03 update wget http://labs.frickle.com/files/ngx_cache_purge-1.3.tar.gz
tar zxf ngx_cache_purge-1.3.tar.gz

Switch to nginx directory
cd nginx-1.0.0
./configure --user=www --group=www --add-module=../ngx_cache_purge-1.3 --prefix=/usr/local/webserver/nginx --with-http_stub_status_module
make;make install

Installation complete!

After the installation in the/usr/local/webserver/nginx four directories, more fastcgi_temp, proxy_temp, scgi_temp and uwsgi_temp.

proxy_temp is a directory where temporary files are stored. You need to see if www has permission to write. You can also set proxy_temp_path in nginx's configuration to specify the directory where temporary files will be stored.

nginx profile reference:

http {
        #proxy_temp_path     /www/proxy_temp;
        # set Web cache name to cache_one, memory cache space size to 100MB, 1 day did not access the content automatically cleared, hard disk cache space size to 10GB.
        proxy_cache_path     /www/proxy_cache     levels=1:2     keys_zone=cache_one:100m inactive=1d max_size=10g;

        server {
                listen             80;
                server_name     s.jb51.net;

                        location / {
                        proxy_cache cache_one;
                        proxy_cache_valid     200 304 12h;
                        proxy_cache_key $uri$is_args$args;
                        proxy_set_header Host     $host;
                        proxy_set_header X-Forwarded-For     $remote_addr;
                        proxy_pass //www.jb51.net;
                        expires             1d;
                                }

                        location ~ /purge(/.*) {
                                allow                             all;
                                allow                             127.0.0.1;
                        #         deny                             all;
                                proxy_cache_purge cache_one $1$is_args$args;
                        }
                        access_log /www/logs/s.log access;
                }
        ......
}

Such access s. jb51. net/images/logo gif, reverse proxy will go to request / / www jb51. net/images/logo gif, kept in memory, then the output.
If logo gif this file has changed, you need to refresh the cache access s. jb51. net purge/images/logo gif, will tip: Successful purge

Key : /images/logo.gif
Path: /www/proxy_cache/39aaa70038997e0e5e77beaa4392848d
If the file has not been cached, 404 Not Found
is prompted
If you have already installed nginx, please be sure to note that it is invalid to restart nginx-s reload! Be sure to boot after -s stop to use the new version of nginx!

I didn't notice that today and spent N hours on it!

/usr/local/webserver/nginx/sbin/nginx -V            
nginx: nginx version: nginx/1.0.0
nginx: built by gcc 4.1.2 20080704 (Red Hat 4.1.2-46)
nginx: configure arguments: --user=www --group=www --add-module=../ngx_cache_purge-1.3 --prefix=/usr/local/webserver/nginx --with-http_stub_status_module

All the time think is to install a success, but repeatedly test all clear failure, very depressed! Obviously open access log, log also did not record any information!
When I continued the test at night, I saw the following error in nginx_error.log:
2011/05/11 21:23:40 [emerg] 20976#0: unknown directive "proxy_cache_purge" in /usr/local/webserver/nginx/conf/nginx.conf:481
I just confirmed that this module is not installed with the original, of course, it can't be used. Later, I saw a reply from someone on a forum that said restart, but reload was invalid. When I thought about the nginx upgrade in the previous paragraph, I found that if I did not use make upgrade upgrade, I had to stop the upgrade and start again to use the new version!

Related articles: