Nginx expires
1. Expires according to file type
# ADD Expires header for static content
Location ~*. (js|css|jpg|jpeg|gif|png|swf) $ {
if (-F $request _filehttp://www.aliyun.com/zixun/aggregation/11696.html ">name") {
Root/data/www/wwwroot/bbs;
Expires 1d;
Break;
}
}
2, according to the judgment of a directory
# Serve static files
Location ~ ^/(images|javascript|js|css|flash|media|static)/{
Root/data/www/wwwroot/down;
Expires 30d;
}
Nginx anti-theft Chain
1. For different file types
#Preventing hot linking of images and other file types
Location ~* ^.+\. (Gif|jpg|png|swf|flv|rar|zip) $ {
Valid_referers None blocked Server_names *.linuxtone.org linuxtone.org http://localhost;
if ($invalid _referer) {
Rewrite ^/http://www.linuxtone.org/images/default/logo.gif;
# return 403;
}
}
2. For different catalogs
location/img/{
root/data/www/wwwroot/bbs/img/;
Valid_referers None blocked Server_names *.linuxtone.org http://localhost baidu.com;
if ($invalid _referer) {
Rewrite ^/http://www.linuxtone.org/images/default/logo.gif;
#return 403;
}
}
3. With the realization of anti-theft chain and expires methods
#Preventing hot linking of images and other file types
Location ~* ^.+\. (Gif|jpg|png|swf|flv|rar|zip) $ {
Valid_referers None blocked Server_names *.linuxtone.org linuxtone.org http://localhost;
if ($invalid _referer) {
Rewrite ^/http://www.linuxtone.org/images/default/logo.gif;
}
Access_log off;
Root/data/www/wwwroot/bbs;
Expires 1d;
Break;
}