#!/bin/bash SITES_AVAILABLE="/etc/nginx/sites-available" SITES_ENABLED="/etc/nginx/sites-enabled" # Create sites-enabled directory if it doesn't exist mkdir -p "$SITES_ENABLED" # Loop through all files in sites-available for site in "$SITES_AVAILABLE"/*; do if [ -f "$site" ]; then site_name=$(basename "$site") target="$SITES_ENABLED/$site_name" # Check if the symlink already exists if [ ! -L "$target" ]; then ln -s "$site" "$target" echo "Linked $site_name" else echo "Site $site_name is already linked" fi fi done # Test nginx configuration nginx -t # Reload nginx if configuration test passes if [ $? -eq 0 ]; then nginx -s reload echo "Nginx configuration reloaded successfully" else echo "Error in nginx configuration" exit 1 fi