2026-03-24 03:30:16 +07:00

36 lines
1.0 KiB
Bash

#!/bin/bash
set -euo pipefail
source "$(dirname "$0")/utils.sh"
require_root
if command -v nginx >/dev/null 2>&1; then
echo "Nginx is already installed: $(nginx -v 2>&1)"
else
echo "Installing Nginx..."
apt-get update -y || { echo "Failed to update package list"; exit 1; }
apt-get install -y nginx || { echo "Failed to install Nginx"; exit 1; }
echo "Nginx installed successfully."
fi
if ! systemctl is-active --quiet nginx; then
echo "Starting Nginx..."
systemctl start nginx || { echo "Failed to start Nginx"; exit 1; }
fi
if ! systemctl is-enabled --quiet nginx; then
echo "Enabling Nginx on boot..."
systemctl enable nginx || { echo "Failed to enable Nginx"; exit 1; }
fi
echo "Nginx status:"
systemctl status nginx --no-pager
if command -v ufw >/dev/null 2>&1; then
ufw allow 'Nginx Full' || { echo "Failed to add UFW rule for Nginx"; exit 1; }
echo "UFW rule for Nginx added."
else
echo "WARNING: UFW is not installed, skipping firewall rule. Run common.sh first."
fi