Created
March 22, 2019 15:32
-
-
Save feinar/30820f8e7f00aff6db267dc64f5a0b19 to your computer and use it in GitHub Desktop.
Nginx+Letsencrypt=Easily
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/bash | |
| # Usage: | |
| # sudo ~/addnew.sh domain.ru | |
| set -e | |
| DOMAIN="$1" | |
| sudo letsencrypt certonly -a webroot --webroot-path=/var/www/html -d ${DOMAIN} -d www.${DOMAIN} | |
| #openssl dhparam -out /etc/pki/nginx/dhparam.pem 4096 | |
| echo -e ' | |
| ********************************************************************* | |
| NGINX config add: | |
| ssl_certificate /etc/letsencrypt/live/${DOMAIN}/fullchain.pem; | |
| ssl_certificate_key /etc/letsencrypt/live/${DOMAIN}/privkey.pem; | |
| ssl_dhparam /etc/pki/nginx/dhparam.pem; | |
| ********************************************************************* | |
| ' |
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
| server { | |
| listen 80 default_server; | |
| listen [::]:80 default_server; | |
| root /var/www/html; | |
| index index.html index.htm index.php; | |
| server_name _; | |
| location / { | |
| try_files $uri $uri/ =404; | |
| } | |
| # For LetsEncrypt: https://letsecure.me/secure-web-deployment-with-lets-encrypt-and-nginx/ | |
| location ~ /.well-known/acme-challenge { | |
| allow all; | |
| } | |
| } |
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
| https://www.digitalocean.com/community/tutorials/how-to-secure-nginx-with-let-s-encrypt-on-ubuntu-16-04 |
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/bash | |
| # This script renews all the Let's Encrypt certificates with a validity < 30 days | |
| # Usage: | |
| # run command: | |
| # sudo crontab -e | |
| # add string | |
| # @daily /home/vpsuser/letsencrypt.cron.sh | |
| # run command: | |
| # chmod +x /home/vpsuser/letsencrypt.cron.sh | |
| NGINX=$(which nginx) | |
| if ! /usr/bin/letsencrypt renew > /var/log/le-renew.log 2>&1 ; then | |
| echo Automated renewal failed: | |
| cat /var/log/le-renew.log | |
| exit 1 | |
| fi | |
| ${NGINX} -t && service nginx restart |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment