Created
January 28, 2025 11:28
-
-
Save sergiycheck/cf3b5d0c378cd471335b7a6d9d4e5858 to your computer and use it in GitHub Desktop.
Install nginx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# !/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