It seems like this is not working:

server_name blabla.bla;    
    location ~* (wp-comments-posts|wp-login)\.php$ {
            if ($http_referer !~ ^(http://$servername) ) {
            return 405;
            }
     }

While

server_name blabla.bla;    
    location ~* (wp-comments-posts|wp-login)\.php$ {
            if ($http_referer !~ ^(http://blabla.bla) ) {
            return 405;
            }
     }

works just fine. Is this expected and if so why? Or am I doing something wrong here?

有帮助吗?

解决方案

Regular expressions are compiled while reading configuration, thus they cannot contain variables.

Also please note:

其他提示

If you have the referer module you might like this one, this will ONLY allow the current server names to be valid referrers. All others will return as 405 error.

        location ~* (wp-comments-post)\.php$ {
            valid_referers server_names;
            
            if ( $invalid_referer ) {
                    return 405;
            }

            ### Do your stuff here
              
        }
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top