当前位置: 首页 > news >正文

上海微网站/枣庄网站建设制作

上海微网站,枣庄网站建设制作,dw做网站首页,商标怎么注册Nginx防盗链 盗链: 如两个网站 A 和 B, B网站引用了A网站上的图片,这种行为就叫做盗链。 防盗链,就是要防止B引用A的图片。 1、nginx 防止网站资源被盗用模块 ngx_http_referer_module区分非正常用户 HTTP Referer是Header的一…
  • Nginx防盗链

盗链:
如两个网站 A 和 B, B网站引用了A网站上的图片,这种行为就叫做盗链。 防盗链,就是要防止B引用A的图片。

1、nginx 防止网站资源被盗用模块

ngx_http_referer_module
  • 区分非正常用户

    HTTP Referer是Header的一部分,当浏览器向Web服务器发送请求的时候,一般会带上Referer,告诉服务器我是从哪个页面链接过来的,服务器借此可以获得一些信息用于处理,例如防止未经允许的网站盗链图片、文件等。因此HTTP Referer头信息是可以通过程序来伪装生成的,所以通过Referer信息防盗链并非100%可靠,但是,它能够限制大部分的盗链情况。

2. 防盗链配置
配置要点:

[root@nginx-server ~]# vim /etc/nginx/nginx.conf
# 日志格式添加"$http_referer"
log_format  main  '$remote_addr - $remote_user [$time_local] "$request" ''$status $body_bytes_sent "$http_referer" ''"$http_user_agent" "$http_x_forwarded_for"';
# valid_referers 使用方式                         
Syntax:     valid_referers none | blocked | server_names | string ...;
Default:    —
Context: server, location
  • none : 允许没有http_referer的请求访问资源; blocked :

  • 允许不是http://开头的,不带协议的请求访问资源—被防火墙过滤掉; server_names :

  • 只允许指定ip/域名来的请求访问资源(白名单);

准备两台机器,一张图片网站服务器

#图片网站服务器:上传图片192.168.1.9[root@nginx-server ~]# cp test.jpg /usr/share/nginx/html/
[root@nginx-server ~]# cd /etc/nginx/conf.d/
[root@nginx-server conf.d]# cp default.conf default.conf.bak
[root@nginx-server conf.d]# mv default.conf nginx.conf
[root@nginx-server conf.d]# vim nginx.confserver {    listen       80;    server_name  localhost;location / {        root   /usr/share/nginx/html;        index  index.html index.htm;    }}
[root@nginx-server conf.d]# nginx -t
[root@nginx-server conf.d]# systemctl restart nginx

访问IP(“-”连接IP为空)

盗链机器配置:192.168.1.10

 [root@nginx-client html]# cat /etc/nginx/conf.d/qf.confserver {listen 80;server_name     localhost;location / {root /usr/share/nginx/html;index index.html;}}[root@nginx-client ~]# cd /usr/share/nginx/html/
[root@nginx-client html]# cp index.html index.html.bak
[root@nginx-client html]# vim index.html
<html>
<head><meta charset="utf-8"><title>qf.com</title>
</head>
<body style="background-color:red;"><img src="http://192.168.1.9/test.jpg"/>
</body>
</html>
[root@nginx-client html]# systemctl restart nginx

测试访问IP
查看图片网站服务器日志:

Referer记录了:连接是1.10这台机器。

#在图片服务器操作

[root@nginx-server conf.d]# vim nginx.conf
server {listen       80;server_name  localhost;location / {root   /usr/share/nginx/html;index  index.html index.htm;valid_referers none blocked www.jd.com;  #允许这些访问if ($invalid_referer) {return 403;}}
}
[root@nginx-server conf.d]# systemctl restart nginx

测试访问IP(域名)
图片服务器查看日志
上面配置并没有允许192.168.1.10这台机器访问。

例二:

[root@nginx-server html]# vim /etc/nginx/conf.d/nginx.conf #将原来的删除掉
server {listen       80;server_name  localhost;location ~  .*\.(gif|jpg|png|jpeg)$ {root  /usr/share/nginx/html;valid_referers none blocked *.qf.com 192.168.1.10;if ($invalid_referer) {return 403;}}
}
#因为none允许为空值访问,所以加不加ip都可以访问,如果把none擦除,就不可以了
重载nginx服务
[root@nginx-server ~]# nginx -s reload

在其中一台机器测试:

#测试不带http_refer:
[root@nginx-server conf.d]# curl -I "http://192.168.1.9/test.jpg"
HTTP/1.1 200 OK
Server: nginx/1.16.1
Date: Mon, 02 Sep 2019 14:02:56 GMT
Content-Type: image/jpeg
Content-Length: 27961
Last-Modified: Mon, 02 Sep 2019 13:23:12 GMT
Connection: keep-alive
ETag: "5d6d17c0-6d39"
Accept-Ranges: bytes#测试带非法http_refer:
[root@nginx-server conf.d]# curl -e http://www.baidu.com -I "http://192.168.1.9/test.jpg"
HTTP/1.1 403 Forbidden
Server: nginx/1.16.1
Date: Mon, 02 Sep 2019 14:03:48 GMT
Content-Type: text/html
Content-Length: 153
Connection: keep-alive#测试带合法的http_refer:
[root@nginx-server conf.d]# curl -e http://www.qf.com -I "http://192.168.1.9/test.jpg"
HTTP/1.1 200 OK
Server: nginx/1.16.1
Date: Mon, 02 Sep 2019 14:04:52 GMT
Content-Type: image/jpeg
Content-Length: 27961
Last-Modified: Mon, 02 Sep 2019 13:23:12 GMT
Connection: keep-alive
ETag: "5d6d17c0-6d39"
Accept-Ranges: bytes[root@ansible-server conf.d]# curl -e http://192.168.1.10 -I "http://192.168.1.9/test.jpg"
HTTP/1.1 200 OK
Server: nginx/1.16.1
Date: Mon, 02 Sep 2019 14:05:36 GMT
Content-Type: image/jpeg
Content-Length: 27961
Last-Modified: Mon, 02 Sep 2019 13:23:12 GMT
Connection: keep-alive
ETag: "5d6d17c0-6d39"
Accept-Ranges: bytes

如果用户直接在浏览器访问你的图片地址,那么图片显示正常,因为它符合规则。
在图片服务器查看日志:

http://www.lbrq.cn/news/819271.html

相关文章:

  • vs2010做网站登陆界面/nba最新交易信息
  • 网站的链接要怎么做/百度推广后台登陆首页
  • 芜湖市住房和城乡建设委员会网站/优化人员配置
  • 怎么样创建自己的小程序/英文外链seo兼职在哪里找
  • 深圳模板网站制作/竞价推广员月挣多少
  • 普通网站制作/发布外链
  • 重庆长寿网站设计公司推荐/国内可访问的海外网站和应用
  • 银行门户网站建设方案/百度收录是什么意思
  • 哪个网站是做韩国化妆品正品/站长统计app进入网址新版小猪
  • 新加坡网站后缀/百度关键词搜索指数
  • 有没有做语文题的网站/小程序开发软件
  • 莱芜做网站/推广工具有哪些
  • 网站seo的推广计划/友情链接赚钱
  • 做动画 的 网站/网站如何进行网络推广
  • 网站大多用源码来做吗/百度小程序对网站seo
  • 微信如何上传wordpress/seo顾问什么职位
  • 网站建设工作部署会/网络宣传推广方法
  • 5网站建设公司/百度学术论文查重
  • 什么样式表一般用于大型网站/搜索引擎推广与优化
  • 有哪些网站结构是不合理的/写手接单平台
  • 手机网站开发公司/职业培训机构排名前十
  • 注册网站请签署意见是写无/谷歌浏览器 免费下载
  • 后台网站要做权限前端还是后台做/一般网站推广要多少钱
  • b站到底是哪个网站/百度新站关键词排名
  • 环保设备公司网站模板/百度快速收录软件
  • 常用python编程软件/windows优化大师怎么卸载
  • 浙江省网站建设公司排名/宁波搜索引擎优化seo
  • 网站备案正常多久/百度企业认证怎么认证
  • 旅游酒店网站建设/秦皇岛seo招聘
  • 贵港网站推广/qq群推广网站免费
  • [python][flask]Flask-Principal 使用详解
  • 【前端】JavaScript文件压缩指南
  • c# openxml 打开加密 的word读取内容
  • 【Word Press进阶】自定义区块的行为与样式
  • ARM 学习笔记(四)
  • 天津大学陈亚楠教授团队 ACS AEM:焦耳热超快合成非平衡态能源材料——毫秒级制备与跨体系性能突破