LNMP下防止图片被盗用浪费流量

一般来说我们的主机或者VPS的流量是有一定限额的,我们网站上面的一些图片可能是流量的主要消耗来源,如果图片资源被人盗链盗用的话那对我们的资源损耗是巨大的。这里简介个简单的办法处理LNMP环境下面的图片盗用问题:

  • server {
  •         listen       80;
  •         server_name demo.neoease.com;
  •         index index.html index.htm index.php;
  •         root  /var/www/demo_neoease_com;
  •         # 这里为图片添加为期 1 年的过期时间, 并且禁止 Google, 百度和本站之外的网站引用图片
  •         location ~ .*\.(ico|jpg|jpeg|png|gif)$ {
  •                 expires 1y;
  •                 valid_referers none blocked demo.neoease.com *.google.com *.baidu.com;
  •                 if ($invalid_referer) {
  •                         return 404;
  •                 }
  •         }
  •         log_format demo.neoease.com '$remote_addr - $remote_user [$time_local] $request'
  •         '$status $body_bytes_sent $http_referer '
  •         '$http_user_agent $http_x_forwarded_for';
  •         access_log  /var/log/demo.neoease.com.log demo.neoease.com;
  • }
  • 推荐站内搜索:阿里云免费虚拟主机、美国免费虚拟主机、域名注册、国外服务器怎么租、主机空间、外国虚拟主机、独立ip虚拟主机、云虚拟主机、美国服务器与日本服务器免费服务器