Skip to content

Instantly share code, notes, and snippets.

@sergiycheck
Created January 28, 2025 11:28
Show Gist options
  • Save sergiycheck/cf3b5d0c378cd471335b7a6d9d4e5858 to your computer and use it in GitHub Desktop.
Save sergiycheck/cf3b5d0c378cd471335b7a6d9d4e5858 to your computer and use it in GitHub Desktop.
Install nginx
# !/bin/sh
# Check if Nginx is installed
if which nginx >/dev/null 2>&1; then
echo "Nginx is installed."
else
echo "Nginx is not installed."
echo "Installing Nginx"
# Install the prerequisites:
sudo apt install curl gnupg2 ca-certificates lsb-release debian-archive-keyring
# Import an official nginx signing key so apt could verify the packages authenticity. Fetch the key:
curl https://nginx.org/keys/nginx_signing.key | gpg --dearmor |
sudo tee /usr/share/keyrings/nginx-archive-keyring.gpg >/dev/null
# Verify that the downloaded file contains the proper key:
gpg --dry-run --quiet --no-keyring --import --import-options import-show /usr/share/keyrings/nginx-archive-keyring.gpg
# The output should contain the full fingerprint 573BFD6B3D8FBC641079A6ABABF5BD827BD9BF62 as follows:
# To set up the apt repository for stable nginx packages, run the following command:
echo "deb [signed-by=/usr/share/keyrings/nginx-archive-keyring.gpg] \
http://nginx.org/packages/debian $(lsb_release -cs) nginx" |
sudo tee /etc/apt/sources.list.d/nginx.list
# To install nginx, run the following commands:
sudo apt update
sudo apt install nginx
# startgin and enabling nginx
sudo systemctl start nginx
sudo systemctl enable nginx
sudo systemctl status nginx
# check if configuration is correct
nginx -t
nginx -s reload
fi
echo "Nginx is installed and configured."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment