lighttpd禁止IP直接访问及防盗链设置

  

1
2
3
4
#禁止IP直接访问lighttpd服务器,禁止其他人的域名解析到lighttpd服务器进行访问,防止恶意解析
$HTTP["host"] !~ "(^|.)yourdomain.com$" {
url.access-deny = ("")
}
1
2
3
4
#禁止非指定网站域名访问服务器,需要开启mod_access模块
$HTTP["referer"] !~ "^($|http://.www\.yourdomain\.com)" {
url.access-deny = ( "" )
}

上面的是直接禁止并返回403状态,但也可以结合

1
url.redirect = ( "(.*)" => "your  URL" )

进行重定向到指定的页面,例如专门弄个防盗链的说明,或者是图片,前提是开启了mod_redirect模块

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#### request method restrictions (v1.5.x ONLY)
# $HTTP["request-method"] !~ "^(GET|HEAD)" {
#     url.access-deny = ( "" )
#  }

#### deny access to unwanted bots or bad clients
# $HTTP["useragent"] =~ "(Google|BadGuy)" {
#   url.access-deny = ( "" )
# }

#### access control list for hidden_dir (not for use behind proxies)
# $HTTP["remoteip"] !~ "127.0.0.1|10.10.10.2|20.10.20.30" {
#     $HTTP["url"] =~ "^/hidden_dir/" {
#       url.access-deny = ( "" )
#     }
#  }

#### url redirect requests for xiaohost.com to www.xiaohost.com
# $HTTP["host"] =~ "^(xiaohost.com)$" {
#         url.redirect = ( "/(.*)" => "http://www.%1/$1")
# }

#### stop image hijacking (anti-hotlinking)
# $HTTP["referer"] !~ "^(http://xiaohost\.com|http://www\.xiaohost\.com)" {
#     url.access-deny = ( ".jpg", ".jpeg", ".png", ".avi", ".mov" )
# }

#### virtual host limits
# $HTTP["host"] !~ "^(xiaohost\.com|www\.xiaohost\.com)" {
#     url.access-deny = ( "" )
#  }

#### stop referer spam
# $HTTP["referer"] =~ "(tarotathome|casinospam)" {
#     url.access-deny = ( "" )
#  }

您必须才能评论!

收藏
新建分类
没有账号? 忘记密码?