nginx.sh 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. #!/bin/bash
  2. clear
  3. if [[ "$EUID" -ne 0 ]]; then
  4. echo -e "\033[1;31m Anda tiada kebenaran untuk menjalankan skrip ini! \033[0m"; exit 1
  5. fi
  6. alamat_hos=$(cat /etc/environment | grep -w 'DOMAIN' | cut -d '=' -f 2)
  7. alamat_emel=$(cat /etc/environment | grep -w 'EMAIL' | cut -d '=' -f 2)
  8. apt-get -qq update
  9. apt-get install nginx -y
  10. mkdir /var/www/html/$alamat_hos
  11. cp /etc/nginx/nginx.conf /etc/nginx/nginx.conf.bak
  12. cat > /etc/nginx/conf.d/cloudflare.conf <<-EOF
  13. set_real_ip_from 173.245.48.0/20;
  14. set_real_ip_from 103.21.244.0/22;
  15. set_real_ip_from 103.22.200.0/22;
  16. set_real_ip_from 103.31.4.0/22;
  17. set_real_ip_from 141.101.64.0/18;
  18. set_real_ip_from 108.162.192.0/18;
  19. set_real_ip_from 190.93.240.0/20;
  20. set_real_ip_from 188.114.96.0/20;
  21. set_real_ip_from 197.234.240.0/22;
  22. set_real_ip_from 198.41.128.0/17;
  23. set_real_ip_from 162.158.0.0/15;
  24. set_real_ip_from 104.16.0.0/13;
  25. set_real_ip_from 104.24.0.0/14;
  26. set_real_ip_from 172.64.0.0/13;
  27. set_real_ip_from 131.0.72.0/22;
  28. set_real_ip_from 2400:cb00::/32;
  29. set_real_ip_from 2606:4700::/32;
  30. set_real_ip_from 2803:f800::/32;
  31. set_real_ip_from 2405:b500::/32;
  32. set_real_ip_from 2405:8100::/32;
  33. set_real_ip_from 2a06:98c0::/29;
  34. set_real_ip_from 2c0f:f248::/32;
  35. real_ip_header CF-Connecting-IP;
  36. EOF
  37. echo '<!DOCTYPE html>
  38. <html lang="en">
  39. <head>
  40. <meta charset="UTF-8" />
  41. <meta http-equiv="X-UA-Compatible" content="IE=edge" />
  42. <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  43. <title>Cybertize Devel</title>
  44. </head>
  45. <body>
  46. <main class="main">
  47. <section class="section">
  48. <article>
  49. <h3 class="article__title">
  50. <a href="/" class="title__link">CYBERTIZE</a>
  51. </h3>
  52. <p class="article_body">
  53. Use my referral link https://m.do.co/c/a28a40414d6a
  54. to gets $100 credit into your DigitalOcean account.
  55. Created by Doctype, Powered by Cybertize
  56. Copyright 2021, Allright reserved.
  57. </p>
  58. <p class="article__footer">
  59. Copyright &#169; 2021 Cybertize, All right reserved.
  60. </p>
  61. </article>
  62. </section>
  63. </main>
  64. </body>
  65. </html>' > /var/www/html/$alamat_hos/index.html
  66. chown -R www-data:www-data /var/www/html/$alamat_hos
  67. echo "server {
  68. listen 80;
  69. listen [::]:80;
  70. root /var/www/html/$alamat_hos;
  71. index index.html index.htm;
  72. server_name $alamat_hos;
  73. location / {
  74. try_files \$uri \$uri/ =404;
  75. }
  76. }" > /etc/nginx/sites-available/$alamat_hos.conf
  77. ln -s /etc/nginx/sites-available/$alamat_hos.conf /etc/nginx/sites-enabled/
  78. apt-get -y -qq install certbot
  79. apt-get -y -qq install python3-certbot
  80. apt-get -y -qq install python3-certbot-nginx
  81. certbot --non-interactive --agree-tos --email $alamat_emel --nginx -d $alamat_hos -d www.$alamat_hos
  82. echo '10 11 * * * root /usr/bin/certbot renew >/dev/null 2>&1' >> /etc/crontab
  83. nginx -t && systemctl restart nginx
  84. echo
  85. echo -e "\033[1;32m Pemasangan nginx pakej telah selesai. \033[0m"
  86. echo