Skip to content

Instantly share code, notes, and snippets.

@muhammedfurkan
Created September 26, 2022 06:39
Show Gist options
  • Save muhammedfurkan/4d67c7dbfb5cf09064cfd112d859c60f to your computer and use it in GitHub Desktop.
Save muhammedfurkan/4d67c7dbfb5cf09064cfd112d859c60f to your computer and use it in GitHub Desktop.
NGINX installation with Let's Encrypt
server {
root /var/www/html;
index index.html index.htm index.nginx-debian.html;
server_name example.com;
include /etc/nginx/mime.types;
}
server {
if ($host = example.com) {
return 301 https://$host$request_uri;
}
listen 80;
listen [::]:80;
server_name example.com;
return 404;
}
#!/bin/bash
# This script is intended to setup the environment for a NGINX Web Server with SSL certificate using Let's Encrypt.
clear
PROJECT_DIR="/etc/nginx/sites-enabled"
CURRENT_DIR=$(pwd)
DOMAIN="example.com"
EMAIL="[email protected]"
# Get latest updates
echo ""
echo "UPDATING SYSTEM..."
echo ""
sudo apt update
echo ""
echo "###### RUNNING NGINX SCRIPT ######"
echo ""
function install_nginx
{
SOFTWARE="nginx"
QUERY="$(sudo dpkg-query -l | grep ${SOFTWARE} | wc -l)"
if [ "$QUERY" -eq 0 ]; then
echo ""
echo "INSTALLING NGINX..."
echo ""
sudo apt -y install $SOFTWARE
# Setup configuration file
sudo cp $CURRENT_DIR/$DOMAIN $PROJECT_DIR/$DOMAIN
# Setup and configure Certbot
sudo apt -y install certbot python3-certbot-nginx
sudo certbot --nginx -d $DOMAIN --non-interactive --agree-tos -m $EMAIL
else
echo "${SOFTWARE} is already installed. skipping..."
fi
}
install_nginx
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment