Configure Nginx to prevent being hotlinking, improve resource utilization, K-brother

Source: Internet
Author: User

July 29, 2016

Nginx Access Log Report a large number of such, after viewing the discovery are Sogou 360QQ pictures hotlinking

49.84.236.135--[29/jul/2016:11:35:58 +0800] "get/upload/2015_06/forum.php http/1.1 302" http://pic.*****.com/d? Query=%e5%a4%8f%e5%ad%a3%e5%a4%a7%e9%94%85%e8%8f%9c%e8%8f%9c%e8%b0%b1&page=1&did=6&st=255&mode =255&phu=http%3a%2f%2fimages.meishij.net%2fp%2f20111001%2f16eebce0733b97334d2ef049b79b0209.jpg&p= 40230500 "" mozilla/5.0 (Windows NT 5.1) applewebkit/537.36 (khtml, like Gecko) chrome/47.0.2526.80 safari/537.36 core/ 1.47.640.400qqbrowser/9.4.8309.400 ""-"^c

What is hotlinking?

Hotlinking means that the service provider does not provide the service itself, bypassing other beneficial end-user interfaces (such as advertisements) by technical means, and providing the end user with the service content of other service providers directly on its own website to defraud the end-user of the browsing and click-through rate. Beneficiaries do not provide resources or provide very little resources, and real service providers do not get any benefits.

302 Status Code

302 redirect also known as 302 for transient transfer (temporarily Moved), English name: 302 redirect. is also considered a temporary redirect (temporary redirect), a Web browser instruction to show the browser is required to display the different URLs, when a Web page experienced a short-term URL changes when used. A temporary redirect is a server-side redirect that can be handled correctly by the search engine spiders .

How to confirm that you have been hotlinking?

First look at whether the status code is 302 or 200, or something else.

You can use TAILF to view it in real time, or you can use awk to count the day.

Then look at this http://pic.*****.com, this is * * Website image URL

I'm brother K!

My record probably means that * * * * * * * * * * * * * * hotlinking My server's images, resulting in wasted resources.


Here's how to prevent the hotlinking from being added to the server in nginx.conf

All of my pictures are many, so type choose gif|jpg|png

Location ~* \. (gif|jpg|png) ${

root/opt/****;

Valid_referers *.****.net ****.net;

if ($invalid _referer) {

return 403;

}

}

Code explanation

Location ~* \. root directory All files (gif|jpg|png) file types to block ${

Valid_referers *.****.net all the 2 level domain name ****.net; Primary domain

I'm brother K.

return 403; You want to set the value of the return

or can be set to customize the figure rewrite ^/http://www.*****.com/retrun.html;

This article is from the "kevinzhang91" blog, make sure to keep this source http://kevinzhang91.blog.51cto.com/12012510/1850726

Configure Nginx to prevent being hotlinking, improve resource utilization, K-brother

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.