Last active
April 1, 2019 17:56
-
-
Save goffinet/33205a18152fe3a87a5cf2d46e65dc3f to your computer and use it in GitHub Desktop.
create_vhost_httpd.sh in Centos7
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
#!/bin/bash | |
#create_vhost_httpd.sh in Centos7 | |
#Variables | |
host=$1 | |
port="80" | |
location="/var/www/html" | |
error_log="/var/log/httpd/${host}-error_log" | |
access_log="/var/log/httpd/${host}-access_log common" | |
#Résolution de nom locale | |
echo "127.0.0.1 ${host}" >> /etc/hosts | |
#Création du dossier et des pages Web | |
mkdir -p ${location}/${host} | |
echo "${host} test page" > ${location}/${host}/index.html | |
#Restauration de la policy Selinux sur le dossier créé | |
restorecon -Rv ${location}/${host} | |
#Création du dossier et des fichiers pour les logs | |
mkdir -p /var/log/httpd | |
touch /var/log/httpd/${host}-error_log | |
touch /var/log/httpd/${host}-access_log | |
#Configuration du vhost | |
cat << EOF > /etc/httpd/conf.d/${host}.conf | |
<VirtualHost *:${port}> | |
ServerAdmin webmaster@${host} | |
DocumentRoot ${location}/${host} | |
ServerName ${host} | |
ErrorLog ${error_log} | |
CustomLog ${access_log} | |
</VirtualHost> | |
EOF | |
#Activation et lancement du service | |
systemctl enable httpd | |
systemctl start httpd | |
systemctl restart httpd | |
#Diganostic | |
curl ${host} | |
httpd -D DUMP_VHOSTS |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment