How to prevent multiple domain names from accessing my website in nginx environment?
phpcn_u1582
phpcn_u1582 2017-05-16 17:25:31
0
3
426

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_u1582
phpcn_u1582

reply all(3)
我想大声告诉你

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.

世界只因有你

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;
    }
}
習慣沉默

Add the following code to the server:

    listen       80 default;
    server_name  _;
    return 500;
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!