论坛风格切换
  • 2979阅读
  • 0回复

[nginx]nginx server 配置较完美防盗链版本 [复制链接]

上一主题 下一主题
离线top
 

发帖
336
金币
0
威望
59
只看楼主 倒序阅读 使用道具 楼主  发表于: 2011-07-19
server
{
   listen       80;
   server_name  bbs.xxxx.com;
   index index.php index.html index.htm;
   root  /www/xxxx_com/xxxx/bbs;

   #limit_conn   crawler  20;    



        location ~ ^/data/.*\.(php|php5)$
    {
        deny all;
    }
    location ~ ^/images/.*\.(php|php5)$
    {
        deny all;
    }
    location ~ ^/attachment/.*\.(php|php5)$
    {
        deny all;
    }              
    location ~ ^/htm_data/.*\.(php|php5)$
    {
        deny all;
    }

   location ~ .*\.(php|php5)?$
   {      
     #fastcgi_pass  unix:/tmp/php-cgi.sock;
     fastcgi_pass  127.0.0.1:9000;
     fastcgi_index index.php;
     include fcgi.conf;
   }





    location ~ .*\.(wma|wmv|asf|mp3|mmf|zip|rar|jpg|gif|png|swf|flv|js|css)$ {
         valid_referers none blocked *.xxxx.com xxxx.com *.qihoo.com qihoo.com baidu.com *.baidu.com *.google.com *.google.cn google.cn google.com;
         if ($invalid_referer) {
         rewrite ^/ http://www.xxxx.com/error.gif;
         #return 403;
          }
        access_log off;
        expires 30d;
        break;
    }


  location / {
    rewrite ^(.*)-htm-(.*)$ $1.php?$2 last;
    rewrite ^(.*)/simple/([a-z0-9\_]+\.html)$ $1/simple/index.php?$2 last;
  }

   #access_log /dev/null;
   #error_log /dev/null;
      log_format  wdtxtaccess  '$remote_addr - $remote_user [$time_local] "$request" '
             '$status $body_bytes_sent "$http_referer" '
             '"$http_user_agent" $http_x_forwarded_for $request_time';
   access_log  /usr/local/nginx/logs/wdtxtaccess.log  wdtxtaccess;
     }


注意 你配置的是 bbs.xxxx.com

         if ($invalid_referer) {
         rewrite ^/ http://www.xxxx.com/error.gif;
         #return 403;
          }

这一段的http://www.xxxx.com/error.gif千万不能使用http://bbs.xxxx.com/error.gif

不然死循环了


快速回复
限100 字节
如果您提交过一次失败了,可以用”恢复数据”来恢复帖子内容
 
提到某人:
选择好友
上一个 下一个