Skip to content

Instantly share code, notes, and snippets.

@yaowenqiang
Forked from dangovorenefekt/blockmetatwitter.md
Created June 26, 2023 13:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yaowenqiang/09cd6a7d9d57e21d6f35c31a97dcd158 to your computer and use it in GitHub Desktop.
Save yaowenqiang/09cd6a7d9d57e21d6f35c31a97dcd158 to your computer and use it in GitHub Desktop.
Block Meta and Twitter (nginx)
  1. Modify /etc/nginx/nginx.conf file
  2. Modify /etc/nginx/sites-available/site.conf file
  3. Create /etc/nginx/useragent.rule file

Where to find user agent strings?
https://explore.whatismybrowser.com/useragents/explore/software_name/facebook-bot/

Test:

[rubin@reaper ~]$ curl -A "instagram" -I https://plrm.podcastalot.com
HTTP/2 503
server: nginx/1.18.0
date: Mon, 26 Jun 2023 06:07:25 GMT
content-type: text/html
content-length: 197
http {
.....
include /etc/nginx/useragent.rules
}
server {
....
if ($badagent) {
return 503;
}
....
}
map $http_user_agent $badagent {
default 0;
~*twitter 1;
~*tweet 1;
~*facebookexternalhit 1;
~*facebot 1;
~*facebook 1;
~*instagram 1;
~*chatgpt 1;
~*ccbot 1;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment