实现的功能有:
1、浏览器里面输入flyear.com 或者 blog.flyear.com 会马上转成www.flyear.com
2、只有同一个站下的网站(*.flyear.com),才能够访问images的图片
3、为某个目录设置防盗链功能
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
|
server {
listen 80;
server_name www.flyear.com;
index index.html index.htm index.php;
root /www/flyear/blog;
client_max_body_size 50m;
access_log /www/logs/blog.flyear.access.log main;
# redirect server error pages to the static page /50x.html
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
if
(!-e $request_filename){
rewrite (.*) /index.php
break
;
}
#rewrite ^/site\/blog\.html\?pid=([\d]+)$ /site/blog/pid/$1.html last;
# rewrite '/site/blog/(.*)' /site/blog.html?pid=$1 last;
# rewrite (.*) /index.php ;
valid_referers none blocked *.flyear.com flyear.com;
location ~ .*\.(gif|jpg|jpeg|png|bmp|swf|attach)$ {
#防盗链,防止其他网站,<img src="我们的图片的url" />
if
($invalid_referer) {
#表示不是直接访问,也没有被防火墙允许,也不是1366768.com过来的,就不给访问资源
return
404;
}
expires 30d;
}
location /images/ {
#如果是正确的url访问,就会有Referer:http://www.1366768.com/site/blog.html
#这里的访问images文件夹,就没有Referer选项
root /www/flyear/blog/images/;
if
($invalid_referer) {
return
404;
}
}
if
($request_uri ~
" "
) {
return
444;
}
location ~ .*\.(js|css)?$ {
expires 1h;
}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
location ~ .*\.php$ {
#root html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
include fastcgi.conf;
client_max_body_size 60m;
set $path_info
""
;
if
($request_uri ~
"^(.+?\.php)(/.+)$"
) {
set $path_info $2;
}
if
($request_uri ~
"^(.+?\.php)(.*)(\?.*)$"
) {
set $path_info $2;
}
}
}
server {
listen 80;
server_name flyear.com blog.flyear.com;
return
301 http:
//www.flyear.com$request_uri;
}
|