-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprovision_nginx_letsencrypt.sh
executable file
·29 lines (24 loc) · 1.12 KB
/
provision_nginx_letsencrypt.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#!/bin/bash
# Remove default server if applicable.
rm -f /etc/nginx/sites-enabled/default
# Deploy location .well-known script.
ln -sf /etc/nginx/sites-available/letsencrypt /etc/nginx/sites-enabled/
# Check nginx configuration and restart the server.
nginx -t && systemctl restart nginx
# Run letsencrypt with email address and accept license.
echo " letsencrypt certonly -a webroot --webroot-path=/var/www/html/ -d $DOMAIN -d www.$DOMAIN --agree-tos --email $EMAIL --renew-by-default"
letsencrypt certonly -a webroot --webroot-path=/var/www/html/ -d $DOMAIN -d www.$DOMAIN --agree-tos --email $EMAIL --renew-by-default
# Create dhparam if it doesn't alrady exist.
if ! [ -f /etc/ssl/certs/dhparam.pem ]; then
sudo -S openssl dhparam -out /etc/ssl/certs/dhparam.pem 2048
fi
# Create a configuration snippet for the website name.
if ! [ -f /etc/nginx/snippets/ssl-$DOMAIN.conf ]; then
echo "
ssl on;
ssl_certificate /etc/letsencrypt/live/$DOMAIN/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/$DOMAIN/privkey.pem;
" > /etc/nginx/snippets/ssl-$DOMAIN.conf
# Restart the nginx server.
nginx -t && systemctl restart nginx
fi