-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvirtual-host-manager.sh
More file actions
46 lines (39 loc) · 1.34 KB
/
virtual-host-manager.sh
File metadata and controls
46 lines (39 loc) · 1.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#!/bin/bash
read -p 'Virtual host: ' host
mkdir -p /var/www/html/$host
echo "Creating HTTP virtual host"
cat <<EOF > /etc/apache2/sites-available/$host.conf
<VirtualHost $host:80>
ServerName $host
ServerAdmin tech@systemstatus.fr
DocumentRoot /var/www/html/$host
ErrorLog /var/log/apache2/$host.error.log
CustomLog /var/log/apache2/$host.access.log combined
RewriteEngine on
RewriteCond %{SERVER_NAME} =$host
RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]
</VirtualHost>
EOF
a2ensite $host.conf
systemctl reload apache2
certbot certonly --apache -d $host
echo "Creating HTTPS virtual host"
cat <<EOF > /etc/apache2/sites-available/$host-le-ssl.conf
<IfModule mod_ssl.c>
<VirtualHost $host:443>
ServerName $host
ServerAdmin tech@systemstatus.fr
DocumentRoot /var/www/html/$host
ErrorLog /var/log/apache2/$host.error.log
CustomLog /var/log/apache2/$host.access.log combined
SSLCertificateFile /etc/letsencrypt/live/$host/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/$host/privkey.pem
Include /etc/letsencrypt/options-ssl-apache.conf
</VirtualHost>
</IfModule>
EOF
a2ensite $host-le-ssl.conf
systemctl reload apache2
chown -R www-data:www-data /var/www/html/$host
echo "Site created"
cd /var/www/html/$host