[linux 2019-07-09] apache配置防盗链

1.检查是否安装 mod_rewrite 模块

apachectl -t -D DUMP_MEDULES |grep rewrite

2.安装 mod_rewrite 模块 (若已安装,则跳过)

#http解压目录
./configure --prefix=/usr/local/httpd --enable-rewrite --enable-so --enable-charset-lite --enable-cgi
make && make install

3.配置 mod_rewrite 模块启用

vim httpd.conf

"/usr/local/httpd/htdcos">
    ...
    Order allow,deny
    Allow from all

    #以下为添加内容
    RewriteEngine On
    RewriteCond %{HTTP_REFERER} !^http://shijt.com/.*$ [NC]
    RewriteCond %{HTTP_REFERER} !^http://shijt.com/$ [NC]
    RewriteCond %{HTTP_REFERER} !^http://www.shijt.com/.*$ [NC]
    RewriteCond %{HTTP_REFERER} !^http://www.shijt.com/$ [NC]
    RewriteRule .*\.(gif|jpg|swf)$ http://www.shijt.com/error.png

4.再次执行第1步代码,检查模块是否安装

5.重启httpd服务

效果如图:

[linux 2019-07-09] apache配置防盗链_第1张图片

 

转载于:https://www.cnblogs.com/shijt/p/11160897.html

你可能感兴趣的:([linux 2019-07-09] apache配置防盗链)