linux KVM虚拟化技术实战与原理解析pdf下载
Nginx 服务 重写 重定向 防盗链
1.转向同一目录:
server {
listen 80; #监听80端口
server_name www.kuitao8.com abc.kuitao8.com;
index index.html index.php;
root /opt/nginx/html;
if ($http_host ~ "^www\.kuitao8\.com$"){
rewrite /(.*) http://abc.kuitao8.com last;
}
}
2.302重定向:
server {
listen 80;
server_name www.kuitao8.com abc.kuitao8.com kuitao8.com;
if ($http_host != "www.kuitao8.com"){
rewrite ^/(.*) http://www.kuitao8.com/$1 permanent;
}
3.301重定向:
server {
listen 80;
server_name www.kuitao8.com abc.kuitao8.com kuitao8.com;
if ($http_host != "www.kuitao8.com"){
rewrite ^/(.*) http://www.kuitao8.com/$1 redirect;
}
4.防盗链(返回412错误)
1)服务器配置文件设置:
location ~* ^.+\.(jpg|jpeg|gif|png|swf|rar|zip)$ {
valid_referers none blocked www.kuitao8.com ;
if ($invalid_referer){
# rewrite ^/ http://www.kuitao8.com/a.gif;
return 412;
break;
}
access_log off; #关闭日志
root /opt/nginx/html; # root
expires 3d; #3天自动清除缓存
break; #中止rewrite不继续匹配
}
服务器上放置一张a.png的图片
2)客户访问中插入一个图片超链接:
<html>
<head>
<title>Welcome to nginx!</title>
</head>
<body bgcolor="white" text="black">
<center><h1>Welcome to nginx!</h1>
<h1> This is the desktop233</h1>
<a href=http://img.kuitao8.com/uploads/2013/1129/20131129053914426.png" >showpng</a> #链接到服务器上的图片
</center>
</body>
</html>
1.转向同一目录:
server {
listen 80; #监听80端口
server_name www.kuitao8.com abc.kuitao8.com;
index index.html index.php;
root /opt/nginx/html;
if ($http_host ~ "^www\.kuitao8\.com$"){
rewrite /(.*) http://abc.kuitao8.com last;
}
}
2.302重定向:
server {
listen 80;
server_name www.kuitao8.com abc.kuitao8.com kuitao8.com;
if ($http_host != "www.kuitao8.com"){
rewrite ^/(.*) http://www.kuitao8.com/$1 permanent;
}
3.301重定向:
server {
listen 80;
server_name www.kuitao8.com abc.kuitao8.com kuitao8.com;
if ($http_host != "www.kuitao8.com"){
rewrite ^/(.*) http://www.kuitao8.com/$1 redirect;
}
4.防盗链(返回412错误)
1)服务器配置文件设置:
location ~* ^.+\.(jpg|jpeg|gif|png|swf|rar|zip)$ {
valid_referers none blocked www.kuitao8.com ;
if ($invalid_referer){
# rewrite ^/ http://www.kuitao8.com/a.gif;
return 412;
break;
}
access_log off; #关闭日志
root /opt/nginx/html; # root
expires 3d; #3天自动清除缓存
break; #中止rewrite不继续匹配
}
服务器上放置一张a.png的图片
2)客户访问中插入一个图片超链接:
<html>
<head>
<title>Welcome to nginx!</title>
</head>
<body bgcolor="white" text="black">
<center><h1>Welcome to nginx!</h1>
<h1> This is the desktop233</h1>
<a href=http://img.kuitao8.com/uploads/2013/1129/20131129053914426.png" >showpng</a> #链接到服务器上的图片
</center>
</body>
</html>
转载请注明:谷谷点程序 » Nginx 服务 重写 重定向 防盗链