how to prevent hotlinking in centos 6.6 + nginx

May 12, 2015 500 views
Linux Commands Configuration Management

Hi, i have a download server, i want to prevent that no other website can use from my download link to their website.

how can i do it?

1 Answer

To prevent other sites from hotlinking your assets you could create a new location block in your Nginx configuration pointing to the directory containing your image file. Then using the valid_referers directive, you can add a list of hosts that are authorized to display the content:

location /assets/ {
     valid_referers none blocked *;
     if ($invalid_referer) {
        return   403;

In this example, any domain besides and its subdomains will recieved a 403 forbidden error when attempting to hotlink an image.

Have another answer? Share your knowledge.