匿名
未登录
登录
Linux78|wiki
搜索
查看“Nginx防盗链”的源代码
来自Linux78|wiki
名字空间
页面
讨论
更多
更多
页面选项
查看
查看源代码
历史
←
Nginx防盗链
因为以下原因,您没有权限编辑本页:
您所请求的操作仅限于该用户组的用户使用:
wiki:用户|用户
您可以查看与复制此页面的源代码。
location ~* \.(gif|jpg|png|swf|flv)$ { root html valid_referers none blocked *.nginx.com; if ($invalid_referer) { rewrite ^/ www.nginx.com #return 404; } } 前面的root可以不要如果你在server{}中有设置可以不需要设定 [root@host ~]# vim /usr/local/nginx/conf/vhost/test.com.conf …… location ~* ^.+\.(gif|jpg|png|swf|flv|rar|zip|doc|pdf|gz|bz2|jpeg|bmp|xls)$ { expires 7d; valid_referers none blocked server_names *.test.com ; #定义referer白名单 if ($invalid_referer) { return 403; #if函数的意思是:如果不是白名单内的域名,返回值:403 } access_log off; } …… [root@host ~]# /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@host ~]# /usr/local/nginx/sbin/nginx -s reload 检查 [root@host ~]# curl -e "http://www.baidu.com/1.txt" -x127.0.0.1:80 -I test.com/baidu.png HTTP/1.1 403 Forbidden Server: nginx/1.12.1 Date: Mon, 11 Sep 2017 11:25:47 GMT Content-Type: text/html Content-Length: 169 Connection: keep-alive 访问被拒绝,防盗链生效
返回至
Nginx防盗链
。
导航
导航
首页
最近更改
随机页面
栏目
Nginx
Kubernetes
Spring Cloud
Wiki工具
Wiki工具
特殊页面
页面工具
页面工具
用户页面工具
更多
链入页面
相关更改
页面信息
页面日志