redbunny

Nginx Bad Bots Blocker Auto Installer (ubuntu)

Feb 6th, 2018
320
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 3.57 KB | None | 0 0
  1. #!/bin/bash
  2. # Nginx Bad Bots Blocker Auto Installer (ubuntu)
  3. # Recode by: c0g4n
  4. # Original code:
  5. # Nginx Bad Bots Blocker Auto Installer (centos)
  6. # Teguh Aprianto
  7. # https://bukancoder | https://teguh.co
  8. # https://raw.githubusercontent.com/teguhmicro/Bots-Blocker-with-Nginx-IP-Tables/master/bots.sh
  9.  
  10. IJO='\e[38;5;82m'
  11. MAG='\e[35m'
  12. RESET='\e[0m'
  13.  
  14. echo -e "$MAG--=[ To start blocking bad bots to access your server, press any key to continue ]=--$RESET"
  15. read answer
  16.  
  17. echo -e "$MAG--=[ Creating bots.d directory ]=--$IJO"
  18. if [ ! -d /etc/nginx/bots.d  ]; then
  19.   mkdir /etc/nginx/bots.d
  20. fi
  21. echo
  22. echo
  23.  
  24. echo -e "$MAG--=[ Download bot list from Bukan Coder Archive ]=--$IJO"
  25. apt-get install wget -y
  26. cd /etc/nginx/bots.d
  27. wget https://arc.bukancoder.co/Nginx-Bad-Bot-Blocker/blacklist.conf.txt -O blacklist.conf
  28. wget https://arc.bukancoder.co/Nginx-Bad-Bot-Blocker/blockips.conf.txt -O blockips.conf
  29. #wget https://pastebin.com/raw/mhM7tarG -O blacklist.conf
  30. #wget https://pastebin.com/raw/Dsk3p83w -O blockips.conf
  31.    
  32. echo
  33. echo
  34.  
  35. echo -e "$MAG--=[ Updating Nginx Configuration ]=--$IJO"
  36. rm -rf /etc/nginx/nginx.conf
  37. cat >/etc/nginx/nginx.conf<<eof
  38. user www-data;
  39. worker_processes auto;
  40. pid /run/nginx.pid;
  41.  
  42. events {
  43.     worker_connections 1024;
  44.     # multi_accept on;
  45. }
  46.  
  47. http {
  48.  
  49.     ##
  50.     # Basic Settings
  51.     ##
  52.  
  53.     sendfile on;
  54.     tcp_nopush on;
  55.     tcp_nodelay on;
  56.     keepalive_timeout 65;
  57.     client_max_body_size 500M;
  58.     types_hash_max_size 2048;
  59.     # server_tokens off;
  60.  
  61.      server_names_hash_bucket_size 64;
  62.     # server_name_in_redirect off;
  63.  
  64.     include /etc/nginx/mime.types;
  65.     default_type application/octet-stream;
  66.  
  67.     ##
  68.     # SSL Settings
  69.     ##
  70.  
  71.     ssl_protocols TLSv1 TLSv1.1 TLSv1.2; # Dropping SSLv3, ref: POODLE
  72.     ssl_prefer_server_ciphers on;
  73.  
  74.     ##
  75.     # Logging Settings
  76.     ##
  77.     log_format main '$remote_addr - $remote_user [$time_local] "$request"'
  78.             '$status $body_bytes_sent "$http_referer"'
  79.             '"$http_user_agent" "$http_x_forwarded_for"';
  80.    
  81.     access_log /var/log/nginx/access.log;
  82.     error_log /var/log/nginx/error.log;
  83.  
  84.     ##
  85.     # Gzip Settings
  86.     ##
  87.  
  88.     gzip on;
  89.     gzip_disable "msie6";
  90.  
  91.     # gzip_vary on;
  92.     # gzip_proxied any;
  93.     # gzip_comp_level 6;
  94.     # gzip_buffers 16 8k;
  95.     # gzip_http_version 1.1;
  96.     # gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript;
  97.  
  98.     ##
  99.     # Virtual Host Configs
  100.     ##
  101.  
  102.     include /etc/nginx/conf.d/*.conf;
  103.     include /etc/nginx/sites-enabled/*;
  104.     include /etc/nginx/bots.d/*;
  105. }
  106.  
  107.  
  108. #mail {
  109. #   # See sample authentication script at:
  110. #   # http://wiki.nginx.org/ImapAuthenticateWithApachePhpScript
  111. #
  112. #   # auth_http localhost/auth.php;
  113. #   # pop3_capabilities "TOP" "USER";
  114. #   # imap_capabilities "IMAP4rev1" "UIDPLUS";
  115. #
  116. #   server {
  117. #       listen     localhost:110;
  118. #       protocol   pop3;
  119. #       proxy      on;
  120. #   }
  121. #
  122. #   server {
  123. #       listen     localhost:143;
  124. #       protocol   imap;
  125. #       proxy      on;
  126. #   }
  127. #}
  128.  
  129. eof
  130. echo
  131. echo
  132.  
  133. echo -e "$MAG--=[ Blocking bots with iptables ]=--$IJO"
  134. cd ~
  135. wget https://arc.bukancoder.co/Bots-Iptables/block.txt -O block
  136. wget https://arc.bukancoder.co/Bots-Iptables/ips.txt -O ips
  137. #wget https://pastebin.com/raw/Ud3bNsQZ -O block
  138. #wget https://pastebin.com/raw/VH3VHeLh -O ips
  139. chmod +x block
  140. ./block
  141.  
  142. echo -e "$MAG--=[ Save iptables ]=--$IJO"
  143. iptables-save
  144.  
  145. echo
  146. echo -e "$MAG--=[Done! Bots has been blocked using Nginx Bad Bots Blocker and iptables]=--$IJO"
Advertisement
Add Comment
Please, Sign In to add comment