配置防盗链php
经过限制referer来实现防盗链的功能html
配置文件增长以下内容linux
<Directory /data/wwwroot/www.123.com>; SetEnvIfNoCase Referer "http://abc.com"; local_ref //设置白名单,即第三方站点,能够引用连接。 SetEnvIfNoCase Referer "http://aaa.com"; local_ref //设置白名单,即第三方站点,能够引用连接。 SetEnvIfNoCase Referer "^$" local_ref //直接复制网址也能够访问。 <filesmatch "\.(txt|doc|mp3|zip|rar|jpg|gif|png)"> Order Allow,Deny Allow from env=local_ref </filesmatch> </Directory>
从新生效配置文件apache
curl -e "http://www.aminglinux.com/123.html"; 自定义referercurl
访问控制-Diretory测试
核心配置文件内容url
<Directory /data/wwwroot/123.com/admin/>; Order deny,allow Deny from all Allow from 127.0.0.1 192.168.137.1 </Directory>
curl测试状态码为403则被限制访问了code
访问控制-FilesMatchhtm
核心配置文件内容图片
<Directory /data/wwwroot/123.com/admin/>; <FilesMatch "index.php(.*)"> Order deny,allow Deny from all Allow from 127.0.0.1 </FilesMatch> </Directory>
apache自定义header
首先安装mod_headers.c,若是是还没编译,直接加上--enable-headers --enable-deflate 便可。
切换到安装的modules/metadata/目录下,
执行/usr/local/apache/bin/apxs -i -a -c mod_headers.c //用apxs添加mod_hearders.c模块
查看配置文件 LoadModule headers_module modules/mod_headers.so是否有开启即去掉井号。
而后在http.conf文件末里面加入
<IFModule mod_headers.c> Header add MyHeader "hello" </IFModule>
而后检查查配置文件语法,即生效下。
/usr/local/apache2.4/bin/apachectl -t /usr/local/apache2.4/bin/apachectl graceful
[root@lamp01 metadata]# curl -I http://localhost HTTP/1.1 200 OK Date: Sun, 24 Dec 2017 00:01:39 GMT Server: Apache/2.4.29 (Unix) Last-Modified: Mon, 11 Jun 2007 18:53:14 GMT ETag: "2d-432a5e4a73a80" Accept-Ranges: bytes Content-Length: 45 MyHeader: hello //有出现这行自定义的则表示成功 Content-Type: text/html