UbuntuApache anti-leech implementation

Source: Internet
Author: User
First, enable the rewrite function of apache: sudovi/etc/apache2/sites-available/default. Modify the following OptionsFollowSymLinksAllowOverrideNone (changed to AllowOverrideAll) optionsindexesfollowsymlinksmulti

First enable the rewrite function of apache:

Sudo vi/etc/apache2/sites-available/default modify the following

Options FollowSymLinks
AllowOverride None (change to AllowOverride All)
  
  
Options Indexes FollowSymLinks MultiViews
AllowOverride None (change to AllowOverride All)
Order allow, deny
AllowFromAll

Then perform apache rewrite and Add. htaccess

RewriteEngine onRewriteCond %{HTTP_REFERER} !^$ [NC]RewriteCond %{HTTP_REFERER} !nobing.cn [NC]RewriteCond %{HTTP_REFERER} !google.com [NC]RewriteCond %{HTTP_REFERER} !baidu.com [NC]RewriteCond %{HTTP_REFERER} !bbs.jiazhuang8.com [NC]RewriteRule .*\.(gif|jpg)$ http://nobing.cn/no.png [R,NC,L] 

Principles:

. The htaccess file will affect its directory and its sub-directories. Therefore, if the content we want to protect (This section uses anti-image leeching as an example, that is, images) is located in multiple directories on the website, you can consider placing the image in the root directory. If the image has a separate subdirectory such as "/images /", you only need to put it in this directory (of course, you can also put it in the root directory ).

Note that if you upload the created. htaccess file to the server through FTP, the transmission mode should be ASCII, not Binary. After uploading to the server, you should change its properties to 644 or "RW-R-R-" Through CHMOD, so that the server can be used and cannot be modified through the browser, of course ,. the Readable attribute of htaccess also has a certain risk: attackers can use it to find the object you want to protect or the location of the authentication file-the solution is to authenticate the file. put htpasswd outside the root directory of the website, so that it cannot be found through the network.
Use. htaccess to disable leeching

Pass. htaccess is a simple method to prevent unauthorized links to non-Html files such as images, compressed files, or videos on websites. By adding a few commands to the file, we can protect our valuable bandwidth. For example, set nobing.cn as follows:

The reference content is as follows: RewriteEngine onRewriteCond% {HTTP_REFERER }! ^$ [NC] RewriteCond% {HTTP_REFERER }!Nobing.cn [NC] RewriteCond% {HTTP_REFERER }!Google.com [NC] RewriteCond% {HTTP_REFERER }!Baidu.com [NC] RewriteCond% {HTTP_REFERER }!Bbs.jiazhuang8.com [NC] RewriteRule.* \. (Gif | jpg) $ http://Nobing.cn/no.png [R, NC, L] 

Briefly explain the preceding statements:

1. RewriteCond % {HTTP_REFERER }! ^ $ [NC]

Allow access with "HTTP_REFERER" Blank, that is, allow users to directly enter the image address in the browser address bar to display the image file. In general, this is optional. However, we recommend that you set this parameter. If you force a request to have "HTTP_REFERER" to access the service, this may cause some problems, for example, when the user accesses the service through the proxy server.

2. RewriteCond % {HTTP_REFERER }! Webeta.cn [NC]

Set the HTTP source that can be accessed, including the website itself, Google, Baidu, bbs.jiazhuang8.com, and so on.

3. RewriteRule. * \. (gif | jpg | png) $ http://nobing.cn/no.png [R, NC, L]

Defines the images to be replaced when a chain is stolen, so that all webpages that steal jpg, gif, and png files will display the No. png files in the root directory. Note: Do not place the displayed image in the anti-leech directory. The smaller the size of the image file, the better. You can use the following statement instead of replacing the image:

RewriteRule. * \. (gif | jpg | png) $-[F]

4. Describe the R, NC, and L

R means turning.

NC is case insensitive.

L indicates that the current redirection ends, and subsequent redirection is not affected by the previous judgment statement.

5. file types to prevent leeching

In the preceding example, gif, jpg, and png are used. You can change or add other file types, such as rar and mov, as needed. Different file extensions are separated by "|.

In this way, we can easily prevent leeching and minimize the fearless consumption of server traffic.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.