Last active
April 4, 2021 23:18
-
-
Save svalleru/6cd2bfb286844ca4152a to your computer and use it in GitHub Desktop.
This file contains hidden or 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
## | |
## Block referer spam on Nginx | |
#check if '/etc/nginx/conf.d/*.conf' is included in nginx.conf | |
root@fooserver:/etc/nginx# cat nginx.conf | grep include | |
include /etc/nginx/mime.types; | |
include /etc/nginx/conf.d/*.conf; | |
include /etc/nginx/sites-enabled/*; | |
#create a blacklist | |
root@fooserver:/etc/nginx# cat conf.d/blacklist.conf | |
#spam websites to blacklist | |
map $http_referer $bad_referer { | |
hostnames; | |
default 0; | |
"~qualitymarketzone.com" 1; | |
"~best-seo-software.xyz" 1; | |
"~traffic2money.com" 1; | |
"~trafficmonetize.org" 1; | |
"~4webmasters.org" 1; | |
"~100dollars-seo.com" 1; | |
"~webmonetizer.net" 1; | |
} | |
root@fooserver:/etc/nginx# cat sites-enabled/default | |
server { | |
listen 80; | |
: | |
server_name findsimilarmovies.com; | |
#don't respond if it's the bad guy | |
if ($bad_referer) { | |
return 444; | |
} | |
: | |
: | |
} | |
root@fooserver:/etc/nginx# sudo service nginx configtest | |
Testing nginx configuration: nginx. | |
root@fooserver:/etc/nginx# sudo service nginx reload | |
Reloading nginx configuration: nginx. | |
#test the new config | |
root@fooserver:/etc/nginx# curl -k --referer http://webmonetizer.net http://www.findsimilarmovies.com | |
curl: (52) Empty reply from server | |
root@fooserver:/etc/nginx# |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment