防盗链

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防盗链与访问控制相关推荐

  1. Nginx防盗链、访问控制、Nginx解析PHP相关配置、Nginx代理

    2019独角兽企业重金招聘Python工程师标准>>> Nginx防盗链 在配置文件里写入以下内容: 用curl测试 访问控制 Nginx限制某些IP不能访问或者只允许某些IP访问. ...

  2. LNMP(nginx防盗链,访问控制,解析php相关配置,Nginx代理,常见502问题)

    一.nginx防盗链 nginx防盗链: [root@lnmp ~]# vim /usr/local/nginx/conf/vhost/test.com.conf   添加以下内容 location ...

  3. Nginx防盗链,Nginx访问控制, Nginx解析php相关配置, Nginx代理

    2019独角兽企业重金招聘Python工程师标准>>> Nginx防盗链 Nginx防盗链配置需要与不记录日志和过期时间结合在一起,因为都用到了location. 打开配置文件,注释 ...

  4. linux的Nginx防盗链、Nginx访问控制、Nginx解析php相关配置、Nginx代理介绍

    Nginx防盗链 思路与httpd一样,配置也不难,但要与过期时间.不记录日志配置结合起来. 1.配置文件内容 [root@gary-tao test.com]# vim /usr/local/ngi ...

  5. Nginx防盗链详细设置

    介绍3种Nginx防盗链的方法,节省你的宽带 一:一般的防盗链如下: location ~* \.(gif|jpg|png|swf|flv)$ { valid_referers none blocke ...

  6. Nginx防盗链的实现原理和实现步骤

    Nginx防盗链的实现原理: 了解防盗链的原理之前,我们得先学习一个HTTP的头信息Referer,当浏览器向web服务器发送请求的时候,一般都会带上Referer,来告诉浏览器该网页是从哪个页面链接 ...

  7. Nginx系列二:(Nginx Rewrite 规则、Nginx 防盗链、Nginx 动静分离、Nginx+keepalived 实现高可用)...

    一.Nginx Rewrite 规则 1. Nginx rewrite规则 Rewrite规则含义就是某个URL重写成特定的URL(类似于Redirect),从某种意义上说为了美观或者对搜索引擎友好, ...

  8. Apache和Nginx防盗链

    要实现防盗链,我们就必须先理解盗链的实现原理,提到防盗链的实现原理就不得不从HTTP协议说起,在HTTP协议中,有一个表头字段叫referer,采用URL的格式来表示从哪儿链接到当前的网页或文件.换句 ...

  9. CentOS服务器下nginx防盗链介绍与配置

    转载来源 : CentOS服务器下nginx防盗链介绍与配置 : safebase.cn/article-256622-1.html 一.防盗链介绍 1.什么是防盗链 简单的说,就是某些不法的网站,通 ...

最新文章

  1. Android 开发笔记“关闭默认键盘”
  2. 《软件工程导论》课后习题答案
  3. inDesign 教程,如何复制文本格式?
  4. matlab希尔伯特变换,利用MATLAB实现Hilbert变换代码
  5. 二元函数可微与可导的关系_二元函数的连续偏导数可微之间的关系
  6. excel打不开服务器上的文件夹,Excel打不开的原因及解决方法汇总
  7. 错误异常too many open files解决方法
  8. 吊销 BTChina 营业执照”后元旦之前可能相继落马的“影视下载”网站名单
  9. html id命名规范,常见的类名id名命名参考规范
  10. 【leetcode】1419. Minimum Number of Frogs Croaking
  11. Lab颜色空间及其应用
  12. 商家入驻天猫商城需要多少钱 天猫入住有哪些常见问题
  13. react 的 render 函数
  14. CTP开发——登录/查询
  15. 06_权限管理(黑)
  16. UBT17:ubuntu安装NotePadqq
  17. 为什么那么多公司在用快速开发平台开发软件?
  18. 【转】RS232、RS485、TTL电平、CMOS电平
  19. VMWare安装CentOs7系统及使用
  20. bat监控程序是否运行

热门文章

  1. matlab中数据可视化,matlab的数据可视化
  2. 涉密电脑痕迹深度清理_Mac空间不足的情况下,该怎么清理呢?
  3. 【代码段】UITableView Section圆角
  4. swift_017(Swift 的枚举)
  5. 故障申报系统php源码,运维不再专业救火 不会PHP照样找出代码性能问题
  6. linux怎么查看mysql安装在哪里_Linux下查看MySQL的安装路径
  7. 如何提高python的运行效率_几个提升Python运行效率的方法之间的对比
  8. 01:初识Redis
  9. Unreachable code
  10. 联合索引和多个单列索引选择