K
K
kachi882020-06-22 15:39:42
Nginx
kachi88, 2020-06-22 15:39:42

How to set up hotlinking in Nginx?

There is a file server on nginx, access to it via http, i.e. site.ru/file.exe and the file is downloaded.

To prevent third-party resources from copying these links to themselves and not loading the server, protection against hotlicking was configured by:

location ~* ^.+\.(iso|img|pkg|exe|zip|rar)$ {
  valid_referers none blocked mysite.ru www.mysite.ru;
  if ($invalid_referer) {
  return https://mysite.ru/;
  }
  }


Everything works, but the problem is that if a link is inserted on a third-party site as "open in a new window", via target="_blank", then this method no longer works and the file is downloaded.
Is there any way to solve this problem?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
K
kachi88, 2020-06-22
@kachi88

In general, the problem was solved quite simply, removed "none" from this line - valid_referers none blocked mysite.ru www.mysite.ru;
And direct links stopped working, including if the link is specified on a third-party site through target="_blank"

D
Dimonchik, 2020-06-22
@dimonchik2013

none
blocked

A
Alexey Sundukov, 2020-06-22
@alekciy

And exactly the goal in "and did not load the server"? Because nginx makes the distribution of statics very efficient and the server does not load it.
And if the real goal is to protect the file from downloading, then it is done differently within the framework of nginx.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question