Skip to content

Instantly share code, notes, and snippets.

@slurpyb
Last active December 10, 2022 03:15
Show Gist options
  • Save slurpyb/4e87f11555b68729a1f491477d7cff06 to your computer and use it in GitHub Desktop.
Save slurpyb/4e87f11555b68729a1f491477d7cff06 to your computer and use it in GitHub Desktop.
Nginx LetsEncrypt Server Block Gen
#!/bin/sh
# https://www.nginx.com/blog/using-free-ssltls-certificates-from-lets-encrypt-with-nginx/
echo "Nginx LetsEncrypt SSL/TLS Config Generator!"; echo "Please enter desired domain ie foo.bar.com, example.com"
read -r domain
echo "Creating Nginx server configuration file for $domain"
echo "server {
listen 80;
listen [::]:80;
root /var/www/html/$domain;
server_name $domain;
}
" > $domain.conf && \
sudo mv $domain.conf /etc/nginx/conf.d/$domain.conf && || exit\
sudo mkdir -p /var/www/html/$domain && || exit \
echo "Checking Nginx Configuration..." \
sudo nginx -t > \
echo "Reloading Nginx\n" \
sudo nginx -s reload> \
echo "Generating Certificate." \
sudo certbot --dry-run --nginx -d $domain > && \
echo "Done!"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment