A small Bash script that automates the initial installation and startup of Nginx on a Debian/Ubuntu VPS.
The script:
- Updates the APT package index.
- Installs Nginx.
- Enables Nginx to start automatically at boot.
- Starts the Nginx service.
- Validates the Nginx configuration.
- Displays the service status.
- Debian or Ubuntu server
sudoprivileges- Internet connectivity
- Bash
Clone the repository:
git clone <repository-url>
cd <repository-directory>Make the script executable:
chmod +x scripts/install-nginx.shRun it:
./scripts/install-nginx.shCheck Nginx:
sudo systemctl status nginxTest the configuration:
sudo nginx -tTest the web server locally:
curl -I http://localhostA successful installation should return an HTTP response from Nginx.
#!/usr/bin/env bash
set -euo pipefail
echo "Updating package index..."
sudo apt update
echo "Installing Nginx..."
sudo apt install -y nginx
echo "Enabling Nginx..."
sudo systemctl enable nginx
echo "Starting Nginx..."
sudo systemctl start nginx
echo "Validating Nginx configuration..."
sudo nginx -t
echo "Nginx status:"
sudo systemctl --no-pager --full status nginx
echo "Nginx installation completed."This script demonstrates basic Linux server administration and Bash automation by turning the initial Nginx deployment into a repeatable procedure.