源码概述:
以下教程主要是通过 nginx
,禁止指定来源网站的链接访问自己的网站,因为经常在统计中看到广告站来路,很影响获取真实的统计信息,所以就想着屏蔽那些广告域名的来路。
1.对于来路为*.xxxx
.com
,全部返回 404,代码如下:
if
($http_referer
~* .*.xxxx
.com
){
return
404;
}
2.对于来路为 xxxx
.com
的链接来路,通过路径转发全部返回到其首页
if
($http_referer
~* xxxx
.com
) {
rewrite
^/ http
://xxxx
.com
/;
}
以上代码可以将它们丢到 location
~ 1.php
(/|$) {}中,案例如下:
location
~ [^/].php
(/|$) {
if
($http_referer
~* .*.xxxx
.com
){
return
404;
}
}
添加代码后只要重启 nginx
,就可以生效。
可以 F12
添加超链接模拟来路测试。
转载请注明:汇站网 » 网站来路域名nginx拦截的几种方法
哈哈,谢谢站长啦!
刚好用到,感谢汇站分享!