Skip to main content

Blocking access from a specific site / ban by Referer

It so happens that you need to block access to the site from a particular site. If nginx is installed on the server, then this problem is solved in a couple of lines.

  if ($ http_referer ~ * "example \ .com") {
 return 403;

We consider in order. if is the if condition. $ http_referer is the referrer, the site from which the transition is made. "Example \ .com" is the address of the site being blocked. Return 403 returns to the browser that has switched from the site an error page 403 - access is denied.

This code needs to be added to the server section of the config and reload this config with the command.

  service nginx reload 

This action will prevent transfers from to your site.

How do you rate the article?
Звёзд: 1Звёзд: 2Звёзд: 3Звёзд: 4Звёзд: 5 ( 1 rating, average: 5.00 out of 5)

” Comment “ Block access from a specific site / ban by Referer

  1. Thank you very much!
    I wrote down for myself so.
    # Ban on http_referer

      if ($ http_referer ~ ^ (|| {
       return 444;

Add a comment

Your email will not be published.