search

Home  >  Q&A  >  body text

How to prevent multiple domain names from accessing my website in nginx environment?

Through traffic source analysis, we found some problems with entering this site through certain domain names and maliciously clicking on ads. How to block these domain names through nginx rules?

if ( $host = "www.xxx.net" or $host = "ads.xxx.com" ) {
    rewrite ^/(.*)$ http://www.sdfdsfgffghgf3sdfsdsdfsdf.com/ permanent;
}

The above rules are invalid, please help an expert write a rule.

phpcn_u1582phpcn_u15822757 days ago485

reply all(3)I'll reply

  • 我想大声告诉你

    我想大声告诉你2017-05-16 17:27:31

    I tried the above methods but failed.
    Excuse me, in which paragraph are the above rules placed?

    I found this rule on some websites:

    <IfModule mod_rewrite.c>
    

    RewriteEngineOn

    Block domain

    RewriteCond %{HTTP_REFERER} ads.acesse.com [NC]
    RewriteRule ^(.*)$ -[F]

    Is it correct if it is converted into nginx rules:

    if ($http_referer ~* "ads.acesse.com"){
    set $rule_0 1$rule_0;
    

    }
    if ($rule_0 = "1"){
    rewrite ^/(.*)$ /-[F];
    }

    Please ask experts to help you judge.

    Required effect: Ban jumping to the target site through a certain domain name, such as jumping from xxx.com to aaa.com to maliciously increase traffic and click on ads:

    Environment: nginx
    Rules:

        if ($http_referer ~* ads\.xxx\.com){
        set $rule_0 1$rule_0;
    }
    if ($rule_0 = "1"){
        rewrite ^/(.*)$ /-[F];
    }
    

    Just put the above rules in the server section. After two days of testing, no redirection has been found through a certain domain name.

    reply
    0
  • 世界只因有你

    世界只因有你2017-05-16 17:27:31

    Yours is just server_name jump,
    According to what you said, it should be judged by the source,
    So you have to judge the refer

        valid_referers none blocked www.mydomain.com *.mydomain.com; 
     
     if ($invalid_referer) { 
        return   403; 
      } 

    The above is a whitelist system, blacklist rules can also be used

      location / {
        if ($http_referer ~* ^xxxxx$) {
           rewrite 493;
        }
    }

    reply
    0
  • 習慣沉默

    習慣沉默2017-05-16 17:27:31

    Add the following code to the server:

        listen       80 default;
        server_name  _;
        return 500;
    

    reply
    0
  • Cancelreply