Created
December 27, 2019 13:58
-
-
Save nfsarmento/eec7fc583ba392a122f26f6b5e20c3e0 to your computer and use it in GitHub Desktop.
nginx block tor
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Brillant! Thank you