Skip to content

Instantly share code, notes, and snippets.

@nfsarmento
Created December 27, 2019 13:58
Show Gist options
  • Save nfsarmento/eec7fc583ba392a122f26f6b5e20c3e0 to your computer and use it in GitHub Desktop.
Save nfsarmento/eec7fc583ba392a122f26f6b5e20c3e0 to your computer and use it in GitHub Desktop.
nginx block tor
wget -qO- https://check.torproject.org/exit-addresses | grep ExitAddress | cut -d ' ' -f 2 | sed "s/^/deny /g; s/$/;/g" > /etc/nginx/conf.d/tor-block.conf; systemctl reload nginx
#next add the following to your nginx site conf
#In nginx you then just include the blacklist.
include /etc/nginx/conf.d/tor-block.conf;
#The file contains statements like this:
#deny 100.0.53.178;
#deny 100.15.114;
...
#You need to reload nginx each time the blacklist changes.
#If you want to redirect to a special page. You can try to utilize the error_page directive in combination with the deny directive.
location / {
error_page 403 = @blacklisted;
include /etc/nginx/conf.d/tor-block.conf;
}
location @blacklisted {
allow all;
return 301 https://www.nuno.ml;
}
#Maybe more easy even like this:
location / {
error_page 403 =301 https://www.nuno.ml;
include /etc/nginx/conf.d/tor-block.conf;
}
@fabien7337
Copy link

Brillant! Thank you

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment