当前位置:首页 > 主机测评 > 正文

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

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

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

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

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

  1. server {
  2. listen 80;
  3. server_name demo.neoease.com;
  4. index index.html index.htm index.php;
  5. root/var/www/demo_neoease_com;
  6. # 这里为图片添加为期 1 年的过期时间, 并且禁止 Google, 百度和本站之外的网站引用图片
  7. location ~ .*\.(ico|jpg|jpeg|png|gif)$ {
  8. expires 1y;
  9. valid_referers none blocked demo.neoease.com *.google.com *.baidu.com;
  10. if ($invalid_referer) {
  11. return 404;
  12. }
  13. }
  14. log_format demo.neoease.com ‘$remote_addr – $remote_user [$time_local] $request’
  15. ‘$status $body_bytes_sent $http_referer ‘
  16. ‘$http_user_agent $http_x_forwarded_for’;
  17. access_log/var/log/demo.neoease.com.log demo.neoease.com;
  18. }

0