-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathvhost.sh
More file actions
75 lines (59 loc) · 2.05 KB
/
Copy pathvhost.sh
File metadata and controls
75 lines (59 loc) · 2.05 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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#!/bin/bash
# Memeriksa apakah pengguna menjalankan script dengan hak akses root
if [ "$EUID" -ne 0 ]; then
echo "Silakan jalankan script ini sebagai root."
exit 1
fi
# Meminta nama domain dari pengguna
read -p "Masukkan nama domain baru (contoh: example.com): " domain
# Meminta pilihan protokol dari pengguna
read -p "Pilih protokol (http/https): " protocol
# Memastikan pilihan protokol valid
if [[ "$protocol" != "http" && "$protocol" != "https" ]]; then
echo "Pilihan protokol tidak valid. Harap pilih 'http' atau 'https'."
exit 1
fi
# Membuat direktori untuk domain baru
mkdir -p /var/www/$domain/public_html
# Mengatur izin untuk direktori
chown -R $USER:$USER /var/www/$domain/public_html
chmod -R 755 /var/www
# Membuat file konfigurasi virtual host untuk Apache
cat <<EOL > /etc/apache2/sites-available/$domain.conf
<VirtualHost *:80>
ServerAdmin webmaster@$domain
ServerName $domain
ServerAlias www.$domain
DocumentRoot /var/www/$domain/public_html
<Directory /var/www/$domain/public_html>
AllowOverride All
</Directory>
ErrorLog \${APACHE_LOG_DIR}/error.log
CustomLog \${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
EOL
# Jika protokol HTTPS dipilih, tambahkan konfigurasi SSL
if [ "$protocol" == "https" ]; then
cat <<EOL >> /etc/apache2/sites-available/$domain.conf
<VirtualHost *:443>
ServerAdmin webmaster@$domain
ServerName $domain
ServerAlias www.$domain
DocumentRoot /var/www/$domain/public_html
SSLEngine on
SSLCertificateFile /path/to/your/certificate.crt
SSLCertificateKeyFile /path/to/your/private.key
SSLCertificateChainFile /path/to/your/chainfile.pem
<Directory /var/www/$domain/public_html>
AllowOverride All
</Directory>
ErrorLog \${APACHE_LOG_DIR}/error.log
CustomLog \${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
EOL
fi
# Mengaktifkan konfigurasi domain baru
a2ensite $domain.conf
# Memuat ulang Apache untuk menerapkan perubahan
systemctl reload apache2
echo "Domain $domain dengan protokol $protocol telah berhasil ditambahkan!"