APP_NAME
- ServerPilot App Name (serverpilot/apps/example)DOMAIN_NAME
- Domain name (example.com)
$ ssh root@SERVER_IP_ADDRESS
Note: This is only necessary when you are setting up a new server, otherwise, skip this step.
$ sudo apt-get update
$ sudo apt-get install software-properties-common
$ sudo add-apt-repository ppa:certbot/certbot
$ sudo apt-get update
$ sudo apt-get install python-certbot-nginx
Note: Stopping NGINX will make sites on the server inaccessible.
# Stop NGINX
$ service nginx-sp stop
# Create the certs
$ certbot certonly --standalone -d DOMAIN_NAME.com -d www.DOMAIN_NAME.com
# Start NGINX
$ service nginx-sp start
The first time you run this command the process could take a few minutes, after it's finished installing, follow on screen instructions and you should get a message similar to:
Congratulations! Your certificate and chain have been saved at /etc/letsencrypt/live/DOMAIN_NAME.com/fullchain.pem.
$ nano /etc/nginx-sp/vhosts.d/APP_NAME.ssl.conf
Note: The filename should match the serverpilot app name. Another way to know is to see what ever letsencrypt named what the files here
/etc/nginx-sp/vhosts.d/APP_NAME.conf
.
server {
listen 443 ssl http2;
listen [::]:443 ssl http2;
server_name DOMAIN_NAME.com www.DOMAIN_NAME.com;
ssl on;
# LetsEncrypt Certs
ssl_certificate /etc/letsencrypt/live/DOMAIN_NAME.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/DOMAIN_NAME.com/privkey.pem;
# Verify Chain of Trust of OCSP Repsonse
# http://nginx.org/en/docs/http/ngx_http_ssl_module.html
ssl_trusted_certificate /etc/letsencrypt/live/DOMAIN_NAME.com/chain.pem;
# Secure SSL protocols and ciphers
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_prefer_server_ciphers on;
ssl_ciphers 'ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-AES256-GCM-SHA384:DHE-RSA-AES128-GCM-SHA256:DHE-DSS-AES128-GCM-SHA256:kEDH+AESGCM:ECDHE-RSA-AES128-SHA256:ECDHE-ECDSA-AES128-SHA256:ECDHE-RSA-AES128-SHA:ECDHE-ECDSA-AES128-SHA:ECDHE-RSA-AES256-SHA384:ECDHE-ECDSA-AES256-SHA384:ECDHE-RSA-AES256-SHA:ECDHE-ECDSA-AES256-SHA:DHE-RSA-AES128-SHA256:DHE-RSA-AES128-SHA:DHE-DSS-AES128-SHA256:DHE-RSA-AES256-SHA256:DHE-DSS-AES256-SHA:DHE-RSA-AES256-SHA:AES128-GCM-SHA256:AES256-GCM-SHA384:AES128-SHA256:AES256-SHA256:AES128-SHA:AES256-SHA:AES:CAMELLIA:DES-CBC3-SHA:!aNULL:!eNULL:!EXPORT:!DES:!RC4:!MD5:!PSK:!aECDH:!EDH-DSS-DES-CBC3-SHA:!EDH-RSA-DES-CBC3-SHA:!KRB5-DES-CBC3-SHA';
ssl_session_timeout 1d;
ssl_session_cache shared:SSL:50m;
# OCSP Stapling
ssl_stapling on;
ssl_stapling_verify on;
# Strict Transport Security
# https://www.chromium.org/hsts
add_header Strict-Transport-Security max-age=15768000;
root /srv/users/serverpilot/apps/APP_NAME/public;
access_log /srv/users/serverpilot/log/APP_NAME/APP_NAME_nginx.access.log main;
error_log /srv/users/serverpilot/log/APP_NAME/APP_NAME_nginx.error.log;
# Proxy Set
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-SSL on;
proxy_set_header X-Forwarded-Proto $scheme;
# Includes
include /etc/nginx-sp/vhosts.d/APP_NAME.d/*.nonssl_conf;
include /etc/nginx-sp/vhosts.d/APP_NAME.d/*.conf;
}
$ service nginx-sp restart
Success! If everything went right your domain should now have SSL.
$ crontab -e
# Certbot renew command every Monday at 5:00 am
0 5 * * 1 certbot renew --pre-hook "service nginx-sp stop" --post-hook "service nginx-sp start" >> /var/log/letsencrypt-renew.log
# Test run
$ certbot renew --dry-run
# Actually renew certs
$ certbot renew
$ certbot certonly --standalone -d domain.com -d www.domain.com -d sub.domain.com -d sub2.domain.com --expand
$ certbot register --update-registration --email <email>