Nginx防盗链与访问控制
防盗链
1、编辑配置文件
[root@plinuxos ~]# vi /usr/local/nginx/conf/vhost/default.conf
server
{
listen 80 default_server;
server_name aaa.com;
index index.html index.htm index.php;
root /data/wwwroot/default;
access_log /tmp/default.log juispan;
location ~* ^.+\.(gif|jpg|png|swf|flv|rar|zip|doc|pdf|gz|bz2|jpeg|bmp|xls)$
{
expires 7d;
valid_referers none blocked server_names *.aaa.com ;
if ($invalid_referer) {
return 403;
}
access_log off;
}
}
2、检查与重载
[root@plinuxos ~]# /usr/local/nginx/sbin/nginx -t
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
[root@plinuxos ~]# /usr/local/nginx/sbin/nginx -s reload
3、测试效果
[root@plinuxos ~]# curl -x127.0.0.1:80 aaa.com/pic001.gif -I
HTTP/1.1 200 OK
Server: nginx/1.12.1
Date: Mon, 14 Aug 2017 21:51:35 GMT
Content-Type: image/gif
Content-Length: 66698
Last-Modified: Sat, 12 Aug 2017 03:29:18 GMT
Connection: keep-alive
ETag: "598e760e-1048a"
Expires: Mon, 21 Aug 2017 21:51:35 GMT
Cache-Control: max-age=604800
Accept-Ranges: bytes
[root@plinuxos ~]# curl -e "http://www.hao123.com" -x127.0.0.1:80 aaa.com/pic001.gif -I
HTTP/1.1 403 Forbidden
Server: nginx/1.12.1
Date: Mon, 14 Aug 2017 21:52:18 GMT
Content-Type: text/html
Content-Length: 169
Connection: keep-alive
访问控制
限制目录
1、编辑配置文件
[root@plinuxos ~]# vi /usr/local/nginx/conf/vhost/default.conf
server
{
listen 80 default_server;
server_name aaa.com;
index index.html index.htm index.php;
root /data/wwwroot/default;
access_log /tmp/default.log juispan;
location /admin/
{
allow 127.0.0.1;
deny all;
}
}
2、检查与重载
[root@plinuxos ~]# /usr/local/nginx/sbin/nginx -t
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
[root@plinuxos ~]# /usr/local/nginx/sbin/nginx -s reload
3、测试效果
[root@plinuxos ~]# mkdir /data/wwwroot/default/admin
[root@plinuxos ~]# echo "test" > /data/wwwroot/default/admin/1.html
[root@plinuxos ~]# curl -x127.0.0.1:80 aaa.com/admin/1.html -I
HTTP/1.1 200 OK
Server: nginx/1.12.1
Date: Mon, 14 Aug 2017 22:13:08 GMT
Content-Type: text/html
Content-Length: 5
Last-Modified: Mon, 14 Aug 2017 22:03:03 GMT
Connection: keep-alive
ETag: "59921e17-5"
Accept-Ranges: bytes
[root@plinuxos ~]# curl -x122.112.253.88:80 aaa.com/admin/1.html -I
HTTP/1.1 403 Forbidden
Server: nginx/1.12.1
Date: Mon, 14 Aug 2017 22:13:13 GMT
Content-Type: text/html
Content-Length: 169
Connection: keep-alive
限制文件
1、编辑配置文件
[root@plinuxos ~]# vi /usr/local/nginx/conf/vhost/default.conf
server
{
listen 80 default_server;
server_name aaa.com;
index index.html index.htm index.php;
root /data/wwwroot/default;
access_log /tmp/default.log juispan;
location ~ .*(upload|image)/.*\.php$
{
deny all;
}
}
2、检查与重载
[root@plinuxos ~]# mkdir /data/wwwroot/default/upload
[root@plinuxos ~]# echo "test" > /data/wwwroot/default/upload/1.php
[root@plinuxos ~]# /usr/local/nginx/sbin/nginx -t
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
[root@plinuxos ~]# /usr/local/nginx/sbin/nginx -s reload
3、测试效果
[root@plinuxos ~]# curl -x127.0.0.1:80 aaa.com/upload/1.php -I
HTTP/1.1 403 Forbidden
Server: nginx/1.12.1
Date: Mon, 14 Aug 2017 22:19:25 GMT
Content-Type: text/html
Content-Length: 169
Connection: keep-alive
限制user-agent
1、编辑配置文件
[root@plinuxos ~]# vi /usr/local/nginx/conf/vhost/default.conf
server
{
listen 80 default_server;
server_name aaa.com;
index index.html index.htm index.php;
root /data/wwwroot/default;
access_log /tmp/default.log juispan;
if ($http_user_agent ~* 'Spider/3.0|YoudaoBot|Tomato') ##星号忽略大小写
{
return 403;
}
}
2、检查与重载
[root@plinuxos ~]# /usr/local/nginx/sbin/nginx -t
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
[root@plinuxos ~]# /usr/local/nginx/sbin/nginx -s reload
3、测试效果
[root@plinuxos ~]# curl -A "apple" -x127.0.0.1:80 aaa.com/upload/1.php -I
HTTP/1.1 200 OK
Server: nginx/1.12.1
Date: Mon, 14 Aug 2017 22:31:09 GMT
Content-Type: application/octet-stream
Content-Length: 5
Last-Modified: Mon, 14 Aug 2017 22:17:17 GMT
Connection: keep-alive
ETag: "5992216d-5"
Accept-Ranges: bytes
[root@plinuxos ~]# curl -A "tomato" -x127.0.0.1:80 aaa.com/upload/1.php -I
HTTP/1.1 403 Forbidden
Server: nginx/1.12.1
Date: Mon, 14 Aug 2017 22:30:26 GMT
Content-Type: text/html
Content-Length: 169
Connection: keep-alive
转载于:https://blog.51cto.com/10158955/1960898
Nginx防盗链与访问控制相关推荐
- Nginx防盗链、访问控制、Nginx解析PHP相关配置、Nginx代理
2019独角兽企业重金招聘Python工程师标准>>> Nginx防盗链 在配置文件里写入以下内容: 用curl测试 访问控制 Nginx限制某些IP不能访问或者只允许某些IP访问. ...
- LNMP(nginx防盗链,访问控制,解析php相关配置,Nginx代理,常见502问题)
一.nginx防盗链 nginx防盗链: [root@lnmp ~]# vim /usr/local/nginx/conf/vhost/test.com.conf 添加以下内容 location ...
- Nginx防盗链,Nginx访问控制, Nginx解析php相关配置, Nginx代理
2019独角兽企业重金招聘Python工程师标准>>> Nginx防盗链 Nginx防盗链配置需要与不记录日志和过期时间结合在一起,因为都用到了location. 打开配置文件,注释 ...
- linux的Nginx防盗链、Nginx访问控制、Nginx解析php相关配置、Nginx代理介绍
Nginx防盗链 思路与httpd一样,配置也不难,但要与过期时间.不记录日志配置结合起来. 1.配置文件内容 [root@gary-tao test.com]# vim /usr/local/ngi ...
- Nginx防盗链详细设置
介绍3种Nginx防盗链的方法,节省你的宽带 一:一般的防盗链如下: location ~* \.(gif|jpg|png|swf|flv)$ { valid_referers none blocke ...
- Nginx防盗链的实现原理和实现步骤
Nginx防盗链的实现原理: 了解防盗链的原理之前,我们得先学习一个HTTP的头信息Referer,当浏览器向web服务器发送请求的时候,一般都会带上Referer,来告诉浏览器该网页是从哪个页面链接 ...
- Nginx系列二:(Nginx Rewrite 规则、Nginx 防盗链、Nginx 动静分离、Nginx+keepalived 实现高可用)...
一.Nginx Rewrite 规则 1. Nginx rewrite规则 Rewrite规则含义就是某个URL重写成特定的URL(类似于Redirect),从某种意义上说为了美观或者对搜索引擎友好, ...
- Apache和Nginx防盗链
要实现防盗链,我们就必须先理解盗链的实现原理,提到防盗链的实现原理就不得不从HTTP协议说起,在HTTP协议中,有一个表头字段叫referer,采用URL的格式来表示从哪儿链接到当前的网页或文件.换句 ...
- CentOS服务器下nginx防盗链介绍与配置
转载来源 : CentOS服务器下nginx防盗链介绍与配置 : safebase.cn/article-256622-1.html 一.防盗链介绍 1.什么是防盗链 简单的说,就是某些不法的网站,通 ...
最新文章
- Android 开发笔记“关闭默认键盘”
- 《软件工程导论》课后习题答案
- inDesign 教程,如何复制文本格式?
- matlab希尔伯特变换,利用MATLAB实现Hilbert变换代码
- 二元函数可微与可导的关系_二元函数的连续偏导数可微之间的关系
- excel打不开服务器上的文件夹,Excel打不开的原因及解决方法汇总
- 错误异常too many open files解决方法
- 吊销 BTChina 营业执照”后元旦之前可能相继落马的“影视下载”网站名单
- html id命名规范,常见的类名id名命名参考规范
- 【leetcode】1419. Minimum Number of Frogs Croaking
- Lab颜色空间及其应用
- 商家入驻天猫商城需要多少钱 天猫入住有哪些常见问题
- react 的 render 函数
- CTP开发——登录/查询
- 06_权限管理(黑)
- UBT17:ubuntu安装NotePadqq
- 为什么那么多公司在用快速开发平台开发软件?
- 【转】RS232、RS485、TTL电平、CMOS电平
- VMWare安装CentOs7系统及使用
- bat监控程序是否运行
热门文章
- matlab中数据可视化,matlab的数据可视化
- 涉密电脑痕迹深度清理_Mac空间不足的情况下,该怎么清理呢?
- 【代码段】UITableView Section圆角
- swift_017(Swift 的枚举)
- 故障申报系统php源码,运维不再专业救火 不会PHP照样找出代码性能问题
- linux怎么查看mysql安装在哪里_Linux下查看MySQL的安装路径
- 如何提高python的运行效率_几个提升Python运行效率的方法之间的对比
- 01:初识Redis
- Unreachable code
- 联合索引和多个单列索引选择