Nginx的location if 太奇怪了
需要请求的图片,其中$station_id是变量
http://host/thumb/200x/$station_id.jpg
http://host/thumb/160x/$station_id.jpg
为了容错,提供了两张默认图片,当$station_id对应的图片找不到的时候,用默认图片替代
http://host/thumb/notfound_160x.jpg
http://host/thumb/notfound_200x.jpg
为此在Nginx里面配置:
location ^~ /thumb/ {
set $notfound "/thumb/notfound_160x.jpg";
if ( $uri ~ "/200x/" ) {
set $notfound "/thumb/notfound_200x.jpg";
}
try_files $uri $notfound =404;
add_header Cache-Control max-age=100;
log_not_found off;
#access_log /usr/local/nginx/logs/a1.log access_format;
access_log off;
}
但是当我们访问: http://host/thumb/160x/$station_id.jpg 的时候配置生效,返回小的默认图片; 访问 http://host/thumb/200x/$station_id.jpg 的时候,就一直提示NotFound
最后被迫无奈,不在loaction中if了,改用两个location
相关推荐
Jaystrong 2020-08-02
gaogaorimu 2020-07-18
FanErZong 2020-07-18
liwf 2020-07-09
thatway 2020-06-28
糊一笑 2020-06-27
tangjianft 2020-06-25
86284851 2020-06-16
LUOPING0 2020-06-16
sshong 2020-06-12
wys 2020-06-10
mmyCSDN 2020-05-28
fanhuasijin 2020-05-28
liuyong00 2020-05-19