Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- # Pastikan skrip dijalankan dengan sudo
- if [[ $EUID -ne 0 ]]; then
- echo "Harap jalankan skrip ini dengan sudo."
- exit 1
- fi
- # Minta input domain dari pengguna
- echo -n "Masukkan domain: "
- read domain
- # Pastikan domain tidak kosong
- if [ -z "$domain" ]; then
- echo "Domain tidak boleh kosong!"
- exit 1
- fi
- # Buat direktori root untuk website
- web_root="/var/www/$domain"
- mkdir -p "$web_root"
- chown -R www-data:www-data "$web_root"
- chmod -R 755 "$web_root"
- # Buat file index.php default
- echo "<?php phpinfo(); ?>" > "$web_root/index.php"
- # Buat file konfigurasi virtual host Nginx
- vhost_conf="/etc/nginx/sites-available/$domain"
- cat > "$vhost_conf" <<EOF
- server {
- listen 80;
- server_name $domain;
- root $web_root;
- index index.php index.html;
- location / {
- try_files \$uri \$uri/ /index.php?\$query_string;
- }
- location ~ \.php$ {
- include snippets/fastcgi-php.conf;
- fastcgi_pass unix:/run/php/php8.2-fpm.sock;
- fastcgi_param SCRIPT_FILENAME \$document_root\$fastcgi_script_name;
- include fastcgi_params;
- }
- location ~* \.(jpg|jpeg|png|gif|ico|css|js|svg|woff|woff2|ttf|otf|eot|mp4|webm|ogg|mp3|wav)$ {
- expires max;
- log_not_found off;
- }
- }
- EOF
- # Aktifkan virtual host
- ln -s "$vhost_conf" /etc/nginx/sites-enabled/
- nginx -t && systemctl reload nginx
- # Instal Certbot jika belum terpasang
- if ! command -v certbot &> /dev/null; then
- apt install -y certbot python3-certbot-nginx
- fi
- # Jalankan Certbot untuk mendapatkan SSL
- certbot --nginx -d "$domain" --email admin@$domain --agree-tos --non-interactive
- # Restart Nginx
- systemctl reload nginx
- echo "Virtual host untuk $domain telah dibuat dan SSL telah dikonfigurasi!"
Advertisement
Add Comment
Please, Sign In to add comment