Py学习  »  NGINX

Nginx防盗链功能技术细节分享

Py站长 • 9 年前 • 4104 次点击  

http://nginx.org/en/docs/http/ngx_http_referer_module.html

如果你的网站会产生很多图片,而你的图片不想让其它网站访问,那么,可以使用 Nginx的 valid_referers 来对网站的图像进行处理,

valid_referers none blocked server_names
               *.example.com example.* www.example.org/galleries/
               ~\.google\.;

例如,上例 ,就是只允许 http://.google. 对您的图像进行访问,这样就可以对您的图像进行保护,也可以节省您的流量 。

上面都比较好理解,大家可能 比较有疑问的是 正则表达式应该如何写。下面举几个例子说明一下:

  • ~sns.qzone.qq. 是指 http://sns.qzone.qq.
  • ~.douban.com/share 是指 http://.douban.com/share
  • ~service.weibo. 是指 http://service.weibo.

那为什么是这样子解析的呢?

由于以下文字

arbitrary string defines a server name and an optional URI prefix. A server name can have an “*” at the beginning or end. During the checking, the server’s port in the “Referer” field is ignored; regular expression the first symbol should be a “~”. It should be noted that an expression will be matched against the text starting after the “http://” or “https://”.

因此,~ 是指 http:// 或 https:// ,所有表达式的开头或结尾均会有 * 来表示 任意值。

Python社区是高质量的Python/Django开发社区
本文地址:http://www.python88.com/topic/507
 
4104 次点击  
文章 [ 1 ]  |  最新文章 9 年前
爱情的枪
Reply   •   1 楼
爱情的枪    9 年前

不错哦~~