#!/usr/bin/env bash # ------------------------------------------------------------------ # Nginx # Source: https://server-installer.de/scripts/nginx # Version: v1.2.0 # Last updated: 2026-09-12 # Target OS: Debian 12, Ubuntu 22.04, Ubuntu 24.04 # ------------------------------------------------------------------ set -euo pipefail log() { printf '\033[36m==>\033[0m %s\n' "$*"; } if [[ $EUID -ne 0 ]]; then echo "Please run as root (sudo)." >&2 exit 1 fi # Arguments NO_FIREWALL="0" while [[ $# -gt 0 ]]; do case "$1" in --no-firewall) NO_FIREWALL=1; shift ;; *) echo "Unknown argument: $1" >&2; exit 1 ;; esac done log "Adding the nginx.org repository" apt-get update -qq apt-get install -y -qq curl gnupg2 ca-certificates lsb-release curl -fsSL https://nginx.org/keys/nginx_signing.key \ | gpg --dearmor -o /usr/share/keyrings/nginx-archive-keyring.gpg . /etc/os-release echo "deb [signed-by=/usr/share/keyrings/nginx-archive-keyring.gpg] \ http://nginx.org/packages/${ID} ${VERSION_CODENAME} nginx" \ > /etc/apt/sources.list.d/nginx.list log "Installing nginx" apt-get update -qq apt-get install -y -qq nginx systemctl enable --now nginx if [[ "$NO_FIREWALL" -eq 0 ]] && command -v ufw >/dev/null; then ufw allow 80/tcp ufw allow 443/tcp fi nginx -v log "Done."