Live data from Hacker News

Using Nginx to block Meta, Twitter and ChatGPT access to your sites

gist.github.com

11–20 of 26 posts

Re: Using Nginx to block Meta, Twitter and ChatGPT access to your sites

#12
If playing around with blocking bots here is one that will block some legit and friendly bots and some bad ones too. This will do nothing for headless chrome acting as a bot. Only use this on silly hobby sites, do not use in production even though most load balancers can do this and much more.

In the main site config redirect anyone not using HTTP/2.0. GoogleBot still doesnt use HTTP/2.0 so this will block Google. Bing is OK though. One could instead use variables to make this multi-condition and make exceptions for their CIDR blocks. Point "auth." DNS record to the same IP and ensure you have a cert for it or a wildcard cert.

    # in main TLS site config:
    # replace apex with your domain and tld with its tld.
    if ($server_protocol != HTTP/2.0) { return 302 https://auth.apex.tld$request_uri; }
Then in your "auth" domain use the same config as the main site minus the redirect but then add basic authentication. Anyone not using HTTP/2.0 can still access the site if they know the right username/password. If you get a lot of bots then have an init script copy the password file into /dev/shm and reference it from there in NGinx to avoid the disk reads.

    # then in the auth.apex.tld config.
    # optionally give a hint replacing i_heart_bots with name_blah_pass_blah
    auth_delay 2s;
    location / {
    auth_basic "i_heart_bots"; auth_basic_user_file /etc/nginx/.pw;
    }
This will block some API command line tools, most bots good or bad, some scanning tools. Some bots will give up prior to 2 seconds so you will get a status 499 instead of 401 in the access logs. Only do this on silly hobby sites. Do not use in production. Only people wearing a T-Shirt like this one [1] may do this in production.

One may be surprised to find that most bots use old libraries that are not HTTP/2.0 enabled. When they catch up we can replace this logic using HTTP/3.0 and UDP. Beyond that we can force people to win a game of tic-tac-toe or Doom over Javascript.

[1] - https://www.amazon.com/Dont-Always-Test-Production-Shirt/dp/...

Re: Using Nginx to block Meta, Twitter and ChatGPT access to your sites

#14
post #13
post #8

Earlier quoted context omitted.

why not both? and check your logs to see who is not complying

That’s a good one. Can non-complaints be subject of a lawsuit?

Why would they be? No contract was signed, no DRM was being broken, they’re simply accessing the website you’re publicly hosting.

Re: Using Nginx to block Meta, Twitter and ChatGPT access to your sites

#16
post #7
post #6

Earlier quoted context omitted.

That assumes they'll honour it, either now or in the future.

If they'd be that malicious, they could also change their bot's UA, so would it really matter?

There are a lot of dumb bots.

Re: Using Nginx to block Meta, Twitter and ChatGPT access to your sites

#18
post #7

Earlier quoted context omitted.

If they'd be that malicious, they could also change their bot's UA, so would it really matter?

There are a lot of dumb bots.

And you think Meta or Twitter's bots would be dumb ?

If they wanted to scrape your site, nobody can prevent them.

Re: Using Nginx to block Meta, Twitter and ChatGPT access to your sites

#19

Earlier quoted context omitted.

There are a lot of dumb bots.

And you think Meta or Twitter's bots would be dumb ? If they wanted to scrape your site, nobody can prevent them.

Kinda. Meta and Twitter want you to join their platforms, they aren't general purpose search engines scraping the entire Internet - they're scraping people that join them. Requests from Meta/Twitter are probably from a link someone put in a post.

ChatGPT can't be an impolite Internet citizen (spoofing UA's) and claim to be using AI for the good for humanity, so they're not going to be dishonest with their user-agent.

Post reply on HN