Advertisement
Guest User

Untitled

a guest
Apr 23rd, 2018
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.74 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. #Variables
  4. ip4=$(/sbin/ip -o -4 addr list eth0 | awk '{print $4}' | cut -d/ -f1)
  5.  
  6. echo ~~Now Installing Virtual Hosts~~
  7. sleep 1
  8. yum -y install httpd
  9. mkdir /etc/httpd/sites-available
  10. mkdir /etc/httpd/sites-enabled
  11. mkdir /var/www/html/sales.jelle.lan
  12. mkdir /var/www/html/support.jelle.lan
  13. mkdir /var/www/html/www.jelle.lan
  14.  
  15. echo "<html>
  16. <head>
  17. <title>Welcome to sales.jelle.lan!</title>
  18. </head>
  19. <body>
  20. <h1>Success! The sales.jelle.lan virtual host is working!</h1>
  21. </body>
  22. </html>" > /var/www/html/sales.jelle.lan/index.html
  23.  
  24. echo "<html>
  25. <head>
  26. <title>Welcome to support.jelle.lan!</title>
  27. </head>
  28. <body>
  29. <h1>Success! The support.jelle.lan virtual host is working!</h1>
  30. </body>
  31. </html>" > /var/www/html/support.jelle.lan/index.html
  32.  
  33. echo "<html>
  34. <head>
  35. <title>Welcome to www.jelle.lan!</title>
  36. </head>
  37. <body>
  38. <h1>Success! www.jelle.lan virtual host is working!</h1>
  39. </body>
  40. </html>" > /var/www/html/www.jelle.lan/index.html
  41.  
  42. echo "<VirtualHost *:80>
  43.  
  44. ServerName sales.jelle.lan
  45. ServerAlias sales.jelle.lan
  46. DocumentRoot /var/www/html/sales.jelle.lan/
  47. ErrorLog /var/www/html/sales.jelle.lan/error.log
  48. CustomLog /var/www/html/sales.jelle.lan/requests.log combined
  49. </VirtualHost>" > /etc/httpd/sites-available/sales.jelle.lan.conf
  50.  
  51. echo "<VirtualHost *:80>
  52.  
  53. ServerName support.jelle.lan
  54. ServerAlias support.jelle.lan
  55. DocumentRoot /var/www/html/support.jelle.lan/
  56. ErrorLog /var/www/html/support.jelle.lan/error.log
  57. CustomLog /var/www/html/support.jelle.lan/requests.log combined
  58. </VirtualHost>" > /etc/httpd/sites-available/support.jelle.lan.conf
  59.  
  60. echo "<VirtualHost *:80>
  61.  
  62. ServerName www.jelle.lan
  63. ServerAlias www.jelle.lan
  64. DocumentRoot /var/www/html/www.jelle.lan/
  65. ErrorLog /var/www/html/www.jelle.lan/error.log
  66. CustomLog /var/www/html/www.jelle.lan/requests.log combined
  67. </VirtualHost>" > /etc/httpd/sites-available/www.jelle.lan.conf
  68.  
  69. ln -s /etc/httpd/sites-available/www.jelle.lan.conf /etc/httpd/sites-enabled/www.jelle.lan.conf
  70. ln -s /etc/httpd/sites-available/support.jelle.lan.conf /etc/httpd/sites-enabled/support.jelle.lan.conf
  71. ln -s /etc/httpd/sites-available/sales.jelle.lan.conf /etc/httpd/sites-enabled/sales.jelle.lan.conf
  72.  
  73. echo "
  74. $ip4 www.jelle.lan
  75. $ip4 sales.jelle.lan
  76. $ip4 support.jelle.lan" >> /etc/hosts
  77.  
  78. touch /var/www/html/www.jelle.lan/error.log
  79. touch /var/www/html/support.jelle.lan/error.log
  80. touch /var/www/html/sales.jelle.lan/error.log
  81. touch /var/www/html/www.jelle.lan/requests.log
  82. touch /var/www/html/support.jelle.lan/requests.log
  83. touch /var/www/html/sales.jelle.lan/requests.log
  84. chcon --reference /var/log/httpd/error_log /var/www/html/www.jelle.lan/error.log
  85. chcon --reference /var/log/httpd/error_log /var/www/html/support.jelle.lan/error.log
  86. chcon --reference /var/log/httpd/error_log /var/www/html/sales.jelle.lan/error.log
  87. chcon --reference /var/log/httpd/access_log /var/www/html/www.jelle.lan/requests.log
  88. chcon --reference /var/log/httpd/access_log /var/www/html/support.jelle.lan/requests.log
  89. chcon --reference /var/log/httpd/access_log /var/www/html/sales.jelle.lan/requests.log
  90. systemctl enable httpd
  91. systemctl restart httpd
  92. clear
  93.  
  94. #loganalyzer
  95. cp -r /var/www/html/loganalyzer /var/www/html/www.jelle.lan
  96.  
  97. #SSL
  98. yum install mod_ssl -y
  99. mkdir /etc/ssl/private
  100. chmod 700 /etc/ssl/private
  101. openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout /etc/ssl/private/Server3.linux.lan.key -out /etc/ssl/certs/Server3.linux.lan.crt
  102. openssl dhparam -out /etc/ssl/certs/dhparam.pem 2048
  103. cat /etc/ssl/certs/dhparam.pem | sudo tee -a /etc/ssl/certs/Server3.linux.lan.crt
  104.  
  105. sed -i '/# General setup for the virtual host, inherited from global configuration/a DocumentRoot "/var/www/html/www.jelle.lan/"' /etc/httpd/conf.d/ssl.conf
  106. sed -i '/# General setup for the virtual host, inherited from global configuration/a ServerName Server3.linux.lan:443' /etc/httpd/conf.d/ssl.conf
  107. sed -i 's/SSLProtocol all -SSLv2/#SSLProtocol all -SSLv2/g' /etc/httpd/conf.d/ssl.conf
  108. sed -i 's/SSLCipherSuite HIGH:MEDIUM:!aNULL:!MD5:!SEED:!IDEA/#SSLCipherSuite HIGH:MEDIUM:!aNULL:!MD5:!SEED:!IDEA/g' /etc/httpd/conf.d/ssl.conf
  109. sed -i 's|SSLCertificateFile /etc/pki/tls/certs/localhost.crt|SSLCertificateFile /etc/ssl/certs/Server3.linux.lan.crt|g' /etc/httpd/conf.d/ssl.conf
  110. sed -i 's|SSLCertificateKeyFile /etc/pki/tls/private/localhost.key|SSLCertificateKeyFile /etc/ssl/private/Server3.linux.lan.key|g' /etc/httpd/conf.d/ssl.conf
  111.  
  112. echo '
  113. # Begin copied text
  114. # from https://cipherli.st/
  115. # and https://raymii.org/s/tutorials/Strong_SSL_Security_On_Apache2.html
  116.  
  117. SSLCipherSuite EECDH+AESGCM:EDH+AESGCM:AES256+EECDH:AES256+EDH
  118. SSLProtocol All -SSLv2 -SSLv3
  119. SSLHonorCipherOrder On
  120. # Disable preloading HSTS for now. You can use the commented out header line that includes
  121. # the "preload" directive if you understand the implications.
  122. #Header always set Strict-Transport-Security "max-age=63072000; includeSubdomains; preload"
  123. Header always set Strict-Transport-Security "max-age=63072000; includeSubdomains"
  124. Header always set X-Frame-Options DENY
  125. Header always set X-Content-Type-Options nosniff
  126. # Requires Apache >= 2.4
  127. SSLCompression off
  128. SSLUseStapling on
  129. SSLStaplingCache "shmcb:logs/stapling-cache(150000)"
  130. # Requires Apache >= 2.4.11
  131. # SSLSessionTickets Off' >> /etc/httpd/conf.d/ssl.conf
  132.  
  133. echo "<VirtualHost *:80>
  134. ServerName www.jelle.lan
  135. Redirect "/" "https://www.jelle.lan"
  136. </VirtualHost>" > /etc/httpd/conf.d/non-ssl.conf
  137.  
  138. systemctl restart httpd.service
  139. apachectl configtest
  140. systemctl restart httpd.service
  141. firewall-cmd --permanent --zone=external --add-service=http
  142. firewall-cmd --permanent --zone=external --add-service=https
  143. firewall-cmd --runtime-to-permanent
  144. firewall-cmd --reload
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement