Linux: apache optimization (5) - Hidden version number

Anti-hotlinking: It is to prevent others from stealing your company’s pictures, files, and videos.

Function: Anti-hotlinking is to prevent others from stealing pictures, files, videos and other related resources in the server. Operation and maintenance personnel can provide the rewrite module through apache for optimization.

Configuration items: 

RewriteEngine ON

##Turn on web page rewriting function

RewriteCond

##Set matching rules

RewriteRule

##Set jump action

Rewrite rules: %{HTTP_REFERER} Browse the link field in the header to store a connection URL, which represents the link from which the required web page is accessed. 

!^

does not start with a field

.*$

ends with any character

NC

not case sensitive

R

Force jump

 Rule matching: If the value of the corresponding variable matches the set rule, it will be processed one by one; if it does not match, subsequent rules will no longer continue to match.


 Environment introduction

Used when configuring, compiling and installing source code packages

./configure --prefix=/usr/local/httpd --enable-cgi --enable-rewrite --enable-so && make && make install

Main website: www.a.com

Hotlinker: www.b.com

 


 Configuration file

vi /usr/local/httpd/conf/httpd.conf

在主配置文件的160行左右

LoadModule rewrite_module modules/mod_rewrite.so

把前面的#去掉

Now go to the main website to configure and enable anti-leeching

 vi /usr/local/httpd/conf/httpd.conf

在<Directory “/usr/local/httpd/htdocs”>					区域中,添加

 RewriteEngine On   			##启用重写功能
    RewriteCond %{HTTP_REFERER} !^http://a.com/.*$ [NC]
    RewriteCond %{HTTP_REFERER} !^http://a.com$ [NC]
    RewriteCond %{HTTP_REFERER} !^http://www.a.com/.*$ [NC]
    RewriteCond %{HTTP_REFERER} !^http://www.a.com$ [NC]
    RewriteRule .*\.(gif|swf|png)$ http://www.a.com/error.jpg [R,NC]

</Directoy> #这个是区域结束,必须要在这个上面,添加到区域外,会无效甚至报错

The final matching result is: Trusted sites of the second, third, fourth and fifth elements can use images on the website; processing sites other than trusted sites, if you access or use gifs and swfs other than the http://www.a.com domain name , png file ending will jump to the redirect page.


test 

The main site is fine

When the hotlinker steals the link again, this picture will be displayed. 

 

Anti-theft successful

Guess you like

Origin blog.csdn.net/w14768855/article/details/135305536