Hotlink protection with rewrite

Hello,
I moved from apache to nginx few quite busy websites and currently I
need help with hotlink protection of swf/flt files. I can send
hotlinking domains to 403, but I want to supply them with for example
hotlink.swf file of my own.

I have not figured out how to rewrite the url in case of referer other
than my own domains. Would anyone be so kind and advise me in this?

Thank you…

Vicky

Posted at Nginx Forum:

Hi !
Something like this :

valid_referers none blocked domain.tld www.domain.tld;

location /flv/
{
if ($invalid_referer) {
rewrite ^ /path/to/hotlink.flv last;
}
}

On Mon, Jan 11, 2010 at 1:29 AM, vicky007 [email protected] wrote:

Hello,
I moved from apache to nginx few quite busy websites and currently I need help with hotlink protection of swf/flt files. I can send hotlinking domains to 403, but I want to supply them with for example hotlink.swf file of my own.

I have not figured out how to rewrite the url in case of referer other than my own domains. Would anyone be so kind and advise me in this?

Thank you…

Vicky


Aleksej Besciokov
EMail/JID: [email protected]
phone: +7 495 7853149

location ~ .(jpg|jpeg|png|gif)$ {
valid_referers server_names blocked none;
if ($invalid_referer) {
rewrite ^(.*)$ /hotlink.png break;
}
}

I using something like it.

Thank you very much, it works perfectly.

vicky

Posted at Nginx Forum:

Samfingcul, I did it as other members here advised me. Try it…

Posted at Nginx Forum:

@vicky007 - hey. can you please tell me how you done it ? thanks

Posted at Nginx Forum:

None of the above methos has helped me.
My files are .swf and .mp4 .
Here is an example of my conf

valid_referers none blocked mysite.com;
location /home/tophi/www/files/
{
if ($invalid_referer) {
rewrite ^ /home/tophi/www/images/hl.png last;
}
}

location ~ .(swf|mp4)$ {
valid_referers server_names blocked .mysite.com;
if ($invalid_referer) {
rewrite ^(.
)$ /home/tophi/www/images/hl.png break;
}
}

please advice
thanks

Posted at Nginx Forum:

Try this:

location ~ .(swf|mp4)$ {
valid_referers server_names blocked .mysite.com;
if ($invalid_referer) {
rewrite ^(.
)$ /hl.png break;
}
}

location =/hl.png {
root /home/tophi/www/images;
}

2011/7/16 tophi [email protected]

So not I’m not able to direct download the file, but videos also can not
be started from the website’s player. I have changed *.mysite.com; also
with mysite.com and www.mysite.com, same result

Try this:

location ~ .(swf|mp4)$ {
valid_referers server_names blocked .mysite.com;
if ($invalid_referer) {
rewrite ^(.
)$ /hl.png break;
}
}

location =/hl.png {
root /home/tophi/www/images;
}

2011/7/16 tophi [email protected]

Posted at Nginx Forum:

try this :

location ~ .(swf|mp4)$ {
valid_referers server_names .mysite.com;
if ($invalid_referer) {
rewrite ^(.
)$ /hl.png break;
}
}

location =/hl.png {
root /home/tophi/www/images;
}

or you can try this one

location ~ .(swf|mp4)$ {
valid_referers server_names none .mysite.com;
if ($invalid_referer) {
rewrite ^(.
)$ /hl.png break;
}
}

location =/hl.png {
root /home/tophi/www/images;
}

hope it useful :slight_smile: