CentOS如何设置nginx防止自己的网站被盗链
Admin 2023-09-23 群英技术资讯 1149 次浏览
[root@lnmp ~]# cd /application/nginx/
[root@lnmp nginx]# cat conf/nginx.conf
worker_processes 1;
events {
worker_connections 1024;
use epoll;
}
http {
server_tokens off;
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
server {
listen 80;
server_name www.liang.com;
root html/www;
index index.php index.html index.htm;
location ~ \.php$ {
root html/www;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
include fastcgi.conf;
}
}
server {
listen 80;
server_name bbs.liang.com;
location / {
root html/bbs;
index index.html index.htm;
}
}
server {
listen 80;
server_name blog.liang.com;
location / {
root html/blog;
index index.html index.htm;
}
}
}
[root@lnmp nginx]# curl www.liang.com/index.html
https://blog.csdn.net/liang_operations/
[root@lnmp nginx]# curl bbs.liang.com
bbs
[root@lnmp nginx]# curl blog.liang.com
blog
3.1www.liang.com为被盗
[root@lnmp nginx]# mkdir html/www/ima
[root@lnmp nginx]# rz
rz waiting to receive.
zmodem trl+C ȡ
100% 277 KB 277 KB/s 00:00:01 0 Errors
[root@lnmp nginx]# mv timg.jpg html/www/ima/
3.2bbs.liang.com盗取www的链接
[root@lnmp nginx]# cat html/bbs/index.html
<img src="http://www.liang.com/ima/timg.jpg">
3.3访问测试
[root@lnmp nginx]#vi conf/nginx.conf
server {
listen 80;
server_name www.liang.com;
root html/www;
index index.php index.html index.htm;
location ~ \.php$ {
root html/www;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
include fastcgi.conf;
}
location ~* \.(gif|jpg|png|swf|flv|bmp)$ {
valid_referers none blocked www.liang.com;
if ($invalid_referer) {
rewrite ^/ http://blog.liang.com/ima/b.jpg;
}
}
}
######
代码详解:
第一行: location ~* \.(gif|jpg|png|swf|flv|bmp)$
其中“gif|jpg|png|swf|flv|bmp”设置防盗链文件类型,自行修改,每个后缀用“|”符号分开!
第二行: valid_referers none blocked www.liang.com;
就是白名单,允许文件链出的域名白名单,自行修改成您的域名! 可以使用子域名,域名与域名之间使用空格隔开!
第五行:rewrite ^/ http://blog.liang.com/ima/b.jpg;
这个图片是盗链返回的图片,也就是替换盗链网站所有盗链的图片。这个图片要放在没有设置防盗链的网站上,因为防盗链的作用,这个图片如果也放在防盗链网站上就会被当作防盗链显示不出来了,盗链者的网站所盗链图片会显示X符号。
这样设置差不多就可以起到防盗链作用了。
[root@lnmp nginx]# ll html/blog/ima/
total 12
-rw-r--r--. 1 root root 11988 Aug 9 2018 b.jpg
这篇关于“CentOS如何设置nginx防止自己的网站被盗链”的文章就介绍到这了,更多相关的内容,欢迎关注群英网络,小编将为大家输出更多高质量的实用文章!
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:mmqy2019@163.com进行举报,并提供相关证据,查实之后,将立刻删除涉嫌侵权内容。
猜你喜欢
天给大家分享linux出现网络故障如何排查的方法,掌握排查linux出现网络故障的技巧还是很有必要的,下文介绍的方法也比较容易理解,感兴趣的朋友就继续往下看吧。
vim操作模式有:1、正常模式,用来浏览和修改文本内容;2、插入模式,用来向文本中添加内容;3、可视模式,相当于高亮选取文本后的普通模式;4、命令模式,用于操作文本文件(不是操作文本文件的内容)。
在linux中,协议栈是计算机网络协议套件的一个具体的软件实现,是网络中各层协议的总和;协议套件中的一个协议通常是只为一个目的而设计的,这样可以使得设计更容易,协议栈反映了一个网络中文件传输的过程。
LINUX怎么使用grep查询指定首尾文件内容?LINUX系统想要查看文件首位内容,该怎么查询呢?我们可以使用grep命令进行查询,下面我们就来看看详细的教程,需要的朋友可以参考下
在Linux系统中调试分辩率的时候,怎样进行调整呢。想要清楚这方面的的操作内容,可以跟随小编来了解了解。希望这篇文章能帮助到朋友们。
成为群英会员,开启智能安全云计算之旅
立即注册Copyright © QY Network Company Ltd. All Rights Reserved. 2003-2020 群英 版权所有
增值电信经营许可证 : B1.B2-20140078 粤ICP备09006778号 域名注册商资质 粤 D3.1-20240008