nginx 1.0.0配ngx_cache_purge实现高效的反向代理

2019-10-17 21:21:13丽君

                allow               127.0.0.1;
            #    deny               all;
                proxy_cache_purge cache_one $1$is_args$args;
            }
            access_log /www/logs/s.log access;
        }
    ......
}

这样访问s.jb51.net/images/logo.gif,反向代理就会去请求//www.jb51.net/images/logo.gif,保存在内存中,然后输出。
如果logo.gif这个文件发生了变化,则需要刷新缓存,访问s.jb51.net/purge/images/logo.gif,就会提示:Successful purge

Key : /images/logo.gif
Path: /www/proxy_cache/39aaa70038997e0e5e77beaa4392848d
如果这个文件没有被缓存过,则提示:404 Not Found

如果是已经安装过nginx了,请一定注意,使用nginx -s reload重启是无效的!一定要-s stop之后再启动,这样才会使用新版本的nginx!

我今天就没注意这点,在这上面化了N个小时!

/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

一直以为是装成功了,但反复测试均清除失败,很郁闷!明明开启了访问日志,日志也没记录任何信息!
晚上继续测试时,在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
才确认这个模块跟本没装上,当然不能用了。后来在一个论坛看到一个人的回复说要restart,但reload是无效的。才想到前段搞nginx升级时就发现,如果不用make upgrade升级,重新编译升级的话,必须停掉,再启动才会使用新的版本!