Seeking help from Nginx experts here.
I want to block people accessing CSS or JS directly from my website. A bit like this: http://assets.behance.net/
I got this reference from ServerFault: https://serverfault.com/a/332493/117595
location ~* (\.jpg|\.png|\.gif|\.jpeg|\.png)$ {
valid_referers none blocked www.example.com example.com;
if ($invalid_referer) {
return 403;
}
}
But a few questions:
In the
valid_referers
, how should I include all the domains from my vhosts directory, which contains the server block for all my domains on this server. (It's a dedicated WHM server with many Cpanel domains.) I would prefer this list of allowed domains to somehow be automated, in case we add more domains in the future.More importantly, how can I make this in the main "http" block, and not server by server (i.e., the vhosts for each domain!)?
Isn't the "IF" condition going to make the Nginx server slower? We have stayed away from all IF blocks so far as I remember reading this has a significant adverse influence on performance.
Thanks!