nginx purge更新缓存404错误
nginx默认安装就会带有反向代理的功能,但想要更好的使用,还得配备frickle.com的ngx_cache_purge模块,用于清除指定URL的缓存。ngx_cache_purge在安装的nginx的时候一起编译进去了,缓存功能一直正常。
文件地址:www.abc.com/includes/templates/zcen/buttons/english/button_in_cart.gif
如下图:

nginx purge 清理缓存失败
但是清理缓存的时候竟然会404
地址:www.abc.com/purge/includes/templates/zcen/buttons/english/button_in_cart.gif

nginx purge 清理缓存失败
百思不得其解,网上遇到nginx清理缓存出现404的用户不在少数,网上一共有如下3中情况:
1、 ngx_cache_purge版本与nginx版本不匹配
换了一个版本的purge,发现依旧无效
2、 nginx启动方法不对
很多人安装完nginx,仅仅reload一次nginx,实际上应该stop之后在start。这不是我的解决方法。
3、 purge未编译到nginx中
肯定不是这个问题,nginx –V能查看编译参数
因为有其他事情,这个事情暂且搁置了,一天闲来无事,看着nginx的配置文件发呆,突然发现自己犯了一个很大的错误:purge的location放错了位置。
错误配置文件:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
|
location
/
{
proxy_pass
http
:
//xxx.ttlsa.com;
include
proxy
.
conf
;
}
location
~
.
*
\
.
(
png
|
jpg
|
gif
|
GIF
|
jpeg
|
JPG
|
PNG
|
bmp
|
BMP
|
JPEG
)
?
$
{
include
proxy
.
conf
;
proxy_pass
http
:
//xxx.ttlsa.com;
expires
1h
;
access_log
off
;
}
location
~
/
purge
(
/
.
*
)
{
allow
127.0.0.1
;
allow
192.168.12.0
/
24
;
proxy_cache_purge
cache
_one
$
host
$
1
$
is_args
$
args
;
}
|
正确配置文件:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
|
location
/
{
proxy_pass
http
:
//xxx.ttlsa.com;
include
proxy
.
conf
;
}
location
~
/
purge
(
/
.
*
)
{
allow
127.0.0.1
;
allow
192.168.12.0
/
24
;
proxy_cache_purge
cache
_one
$
host
$
1
$
is_args
$
args
;
}
location
~
.
*
\
.
(
png
|
jpg
|
gif
|
GIF
|
jpeg
|
JPG
|
PNG
|
bmp
|
BMP
|
JPEG
)
?
$
{
include
proxy
.
conf
;
proxy_pass
http
:
//xxx.ttlsa.com;
expires
1h
;
access_log
off
;
}
|
细心的兄弟很快能发现我把purge的位置放错了,每次更新图片缓存的时候它都只匹配到了图片后缀的location,接着就返回了404,根本没有匹配到purge这个location的机会。把purge调到前面就正常了。
成长的对话版权声明:以上内容作者已申请原创保护,未经允许不得转载,侵权必究!授权事宜、对本内容有异议或投诉,敬请联系网站管理员,我们将尽快回复您,谢谢合作!