Specify Direct Link Deny Domain on Nginx

Asked 2 years ago, Updated 2 years ago, 73 views

I would like to reject the direct link of the image in Nginx.There are many tutorials on how to deny non-domains referrals using valid_refer, but I don't know how to deny direct links in the specified domain.Can invalid_refer do the same thing?

 location~.(gif|png|jpe?g)${
     invalid_refer none blocked to *badsite.com;
     if($invalid_refer){
        return403;
    }
}

nginx

2022-09-30 16:26

1 Answers

The $invalid_refer variable appears to be set by the valid_refers directive, but I am not good at setting negative regular expressions in the valid_refer directive, so what do you think about implementing it like this?

map$http_refer$block_by_refer{
    ~^https?://bad.example.com/1;
    default0;
}
...
location~\.(gif|png|jpe?g)${
    if($block_by_refer){
        return403;
    }
}


2022-09-30 16:26

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.