메뉴 건너뛰기

컴' 게시판

본문시작

IT/개발
2013.09.27 05:29

Hotlink protection in Nginx

조회 수 17156 추천 수 0 댓글 0

Hotlinked files can be a major cause for bandwidth leeching for some sites. Here’s how you can hotlink protect your images and other file types using a simple location directive in your Nginx configuration file :

location ~ .(jpe?g|png|gif)$ {
     valid_referers none blocked mysite.com *.mysite.com;
     if ($invalid_referer) {
        return   403;
    }
}

Use the pipe (“|”) to separate file extensions you want to hotlink protect.

The valid_referers directive contains the list of site for whom hotlinking is allowed. Here is an explanation of the parameters for the valid_referers directive :

  • none - Matches the requests with no Referrer header.
  • blocked - Matches the requests with blocked Referrer header.
  • *.mydomain.com - Matches all the sub domains of mydomain.com. Since v0.5.33, * wildcards can be used in the server names.

You can also tweak the location directive for blocking files from a specific directory. Like this :

location /images/ {
     valid_referers none blocked mysite.com *.mysite.com;
     if ($invalid_referer) {
        return   403;
    }
}

This will hotlink protect every file in any images directory.

If you find this article helpful, please consider making a donation.


링크 : http://nginxlibrary.com/hotlink-protection/


  1. 13
    Mar 2014
    12:23

    욕심버리기

    Category개인자료 By꿈자 Reply0 Views56326 Votes0
    Read More
  2. 20
    Feb 2014
    04:51

    Git 리비전

    CategoryIT/개발 By꿈자 Reply0 Views0 Votes0 secret
    Read More
  3. 04
    Feb 2014
    06:04

    AWS 속도면과 가격대비 합...

    CategoryIT/개발 By꿈자 Reply0 Views15329 Votes0
    Read More
  4. 29
    Jan 2014
    01:33

    Code Completion for CodeI...

    CategoryIT/개발 By꿈자 Reply0 Views17 Votes0
    Read More
  5. 23
    Jan 2014
    08:26

    ubuntu CPU사량량 체크

    CategoryIT/개발 By꿈자 Reply1 Views0 Votes0 secret
    Read More
  6. 21
    Jan 2014
    04:27

    How to simplify the way t...

    CategoryIT/개발 By꿈자 Reply0 Views15403 Votes0
    Read More
  7. 25
    Nov 2013
    02:40

    MAC Terminal 색상변경

    CategoryIT/개발 By꿈자 Reply0 Views34817 Votes0
    Read More
  8. 27
    Sep 2013
    05:29

    Hotlink protection in Nginx

    CategoryIT/개발 By꿈자 Reply0 Views17156 Votes0
    Read More
  9. 26
    Sep 2013
    01:53

    PM(기획자)과 일하는 방법

    CategoryIT/개발 By꿈자 Reply0 Views16839 Votes0
    Read More
  10. 25
    Sep 2013
    04:56

    한번쯤 확인해봐야 할 UI체...

    CategoryIT/개발 By꿈자 Reply0 Views17569 Votes0
    Read More
Board Pagination Prev 1 ... 7 8 9 10 11 ... 17 Next
/ 17