0

In the past, this works perfectly:

#domain1.com
location /files/ {
    valid_referers none blocked domain1.com domain2.com domain3.com;
    if ($invalid_referer) {
        return 403;
    }
    if (!-e $request_filename) {
        rewrite ^(.*)$ https://domain2.com/files/$1 redirect; 
    }
}

but doesn't work now after I upgraded nginx

I found this, seems if not working with new nginx version: https://www.nginx.com/resources/wiki/start/topics/depth/ifisevil/

I also found this hack to solve problem: https://agentzh.blogspot.com/2011/03/how-nginx-location-if-works.html

But I don't know how to make it works.

This is my .htaccess file:

RewriteEngine On
RewriteCond %{HTTP_REFERER} !domain1\.com [NC]
RewriteCond %{HTTP_REFERER} !domain2\.com [NC]
RewriteCond %{HTTP_REFERER} !domain3\.com [NC]
RewriteRule \.rar$ - [F,NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ http://domain2.com/file/$1 [L,R,NC]
Gerald Schneider
  • 19,757
  • 8
  • 52
  • 79
  • 1
    What do you mean by "doesn't work"? That really gives no useful information. Exactly what is happening? – Michael Hampton Sep 28 '21 at 10:16
  • @Michael Hampton 1. Last, before update nginx, if i browse directly or click on link from other sites (except domain1.com domain2.com domain3.com) it show Forbiden page. Now not, it can show normally 2. Last if http://domain1.com/file.html not exist it redirect to http://domain2.com/file.html Now, not redirect – Phạm Thanh Tùng Sep 28 '21 at 10:38
  • That is strange. Your `location` block looks like it should do this successfully. Maybe there is something else in your nginx configuration that causes the problem. Please post the complete output from the command `nginx -T` – Michael Hampton Sep 28 '21 at 10:44
  • Thanks for your help Michael Hampton. I think I must re-install server without nginx :) – Phạm Thanh Tùng Sep 28 '21 at 12:54

0 Answers0