惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

S
Secure Thoughts
Security Latest
Security Latest
Simon Willison's Weblog
Simon Willison's Weblog
O
OpenAI News
GbyAI
GbyAI
L
LINUX DO - 最新话题
A
Arctic Wolf
T
Tor Project blog
G
GRAHAM CLULEY
I
InfoQ
博客园_首页
IT之家
IT之家
The Register - Security
The Register - Security
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
P
Proofpoint News Feed
The GitHub Blog
The GitHub Blog
Blog — PlanetScale
Blog — PlanetScale
N
Netflix TechBlog - Medium
K
Kaspersky official blog
博客园 - 三生石上(FineUI控件)
S
SegmentFault 最新的问题
U
Unit 42
PCI Perspectives
PCI Perspectives
量子位
P
Palo Alto Networks Blog
S
Securelist
T
Troy Hunt's Blog
博客园 - 【当耐特】
Recorded Future
Recorded Future
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
S
Security Affairs
Engineering at Meta
Engineering at Meta
T
The Blog of Author Tim Ferriss
博客园 - 聂微东
罗磊的独立博客
N
News and Events Feed by Topic
人人都是产品经理
人人都是产品经理
B
Blog RSS Feed
NISL@THU
NISL@THU
C
Cisco Blogs
T
Threatpost
有赞技术团队
有赞技术团队
Forbes - Security
Forbes - Security
Hugging Face - Blog
Hugging Face - Blog
Last Week in AI
Last Week in AI
T
The Exploit Database - CXSecurity.com
Cloudbric
Cloudbric
Cyberwarzone
Cyberwarzone
Google DeepMind News
Google DeepMind News
C
Cyber Attacks, Cyber Crime and Cyber Security

Rat's Blog - Apache

Linux VPS使用Webbench/Apache-ab进行网站压力测试 - Rat's Blog Apache环境强制http 301跳转https的方法 - Rat's Blog CentOS 6系统Apache环境配置SSL证书教程 - Rat's Blog apache端口被异常占用导致无法启动的解决方法 - Rat's Blog
Linux VPS下Nginx与Apache环境防盗链设置方法 - Rat's Blog
博主: Rat's · 2015-03-02 · via Rat's Blog - Apache

说明:很多人的VPS流量有限,有的人在VPS中放了一首MP3用来作为背景音乐,但被搜索引擎列为试听/下载地址,放的图片和文件地址也会别人盗用,可想而知流量会消耗多快,这时候我们需要设置防盗链来阻止这样的事发生。

方法

根据我们搭建的系统环境不同,我们在NginxApache中设置防盗链的方法也是不同的。

1、Nginx防盗链方法:

location ~ .*\.(gif|jpg|jpeg|png|bmp|swf|mp3|wav|zip|rar)$
{
valid_referers none blocked moerats.com *.moerats.com;
if ($invalid_referer)
{
return 403;
}
expires 30d;
}

在我们网站所在的配置文件conf中添加以上代码,添加后重启nginx就可以生效,网址替换成自己的。

2、Apache防盗链方法:

RewriteEngine On
RewriteCond %{HTTP_REFERER} !^http://moerats.com/.*$ [NC]
RewriteCond %{HTTP_REFERER} !^http://moerats.com$ [NC]
RewriteCond %{HTTP_REFERER} !^http://www.moerats.com/.*$ [NC]
RewriteCond %{HTTP_REFERER} !^http://www.moerats.com$ [NC]
RewriteRule .*\.(gif|jpg|jpeg|png|bmp|swf|mp3|wav|zip|rar)$ http://www.moerats.com/404.html [R,NC]

把上面代码中的网址替换成自己的,然后提交至网站的根目录.htaccess文件中添加上述代码即可生效。


版权声明:本文为原创文章,版权归 Rat's Blog 所有,转载请注明出处!

本文链接:https://www.moerats.com/archives/141/

如教程需要更新,或者相关链接出现404,可以在文章下面评论留言。

Vultr新用户注册送100美元/16个机房按小时计费,支持支付宝,【点击查看】。