Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am using owncloud and sometimes share links with people via Facebook.

I am concerned with automatic crawling, so I would like to deny facebook access to my server (it visits all links in order to get preview pictures, preview texts, etc.)

Is there a way to do this in nginx? Like via hostname or agent? (I feel like using IPs is a game one cannot win).

If not: Is there some other way like a blacklist project with a list of gov-, FB-, etc. -IPs for iptables?

share|improve this question
If I understand correctly you need only block the referer try something like this – user Jul 5 '13 at 11:57

tcp wrappers? I believe that can do host/domain based denies. Also have you tried a simple robots.txt would be surprised if facebook didn't respect them. I'd think they could not afford the controversy of ignoring them.

share|improve this answer

nginx supports the $http_user_agent value out of the box:

if ($http_user_agent ~* (facebook|google)) {

Hostname verification can be done via 3rd party module — ngx_http_rdns_module: (

Like this:

location / {
    rdns double;
    rdns_deny ^.*\.(facebook|google)\.com$;
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.