Installing and maintaining an Open-SSL Certificate

Configure NginX (with initial settings, before SSL)

server {
    server_name; #or whatever domain
    listen 80;
    listen [::]:80;

    location ~ /\.well-known/acme-challenge {
        default_type "text/plain";
        root /www/sslcert; #or wherever dir
        try_files /$uri /;


Then install certificate

sudo apt-get install software-properties-common
sudo add-apt-repository ppa:certbot/certbot
sudo apt-get update
sudo apt-get install certbot
mkdir /www/sslcert #or wherever you want to put it
certbot certonly --webroot --agree-tos --no-eff-email --email -w /www/sslcert -d

If paths in server configuration are correct. Notice it says /etc/letsencrypt/live/

Using the webroot path /www/sslcert for all unmatched domains.
Waiting for verification...
Cleaning up challenges

 - Congratulations! Your certificate and chain have been saved at:
   Your key file has been saved at:
   Your cert will expire on 2018-05-25. To obtain a new or tweaked
   version of this certificate in the future, simply run certbot
   again. To non-interactively renew *all* of your certificates, run
   "certbot renew"
 - If you like Certbot, please consider supporting our work by:

   Donating to ISRG / Let's Encrypt:
   Donating to EFF:          

Test that renewal will work:

sudo certbot renew --dry-run

Create script that /etc/crontab runs weekly, to auto-update

sudo certbot renew
service nginx restart

Create config snippet in /etc/nginx/snippets/ssl.conf to use later:

ssl_session_timeout 1d;
ssl_session_cache shared:SSL:50m;
ssl_session_tickets off;

ssl_protocols TLSv1.2;
ssl_ecdh_curve secp384r1;
ssl_prefer_server_ciphers on;

ssl_stapling on;
ssl_stapling_verify on;

add_header Strict-Transport-Security "max-age=15768000; includeSubdomains; preload";
add_header X-Frame-Options DENY;
add_header X-Content-Type-Options nosniff;

Update server config to include port 443 and app logic

server {
    listen 80;
    listen [::]:80;
    listen 443 ssl http2;
    listen [::]:443 ssl http2;
    ssl_certificate /etc/letsencrypt/live/;
    ssl_certificate_key /etc/letsencrypt/live/;
    ssl_trusted_certificate /etc/letsencrypt/live/;
    include /etc/nginx/snippets/ssl.conf;

    location / {
        proxy_set_header   X-Forwarded-For $remote_addr;
        proxy_set_header   Host $http_host;
        proxy_pass         "http://localhost:3000";
    location /api/v1 {
        proxy_set_header   X-Forwarded-For $remote_addr;
        proxy_set_header   Host $http_host;
        proxy_pass         "http://localhost:1080";

    location /static {
        root /www/jsjobs/app/build/public;
        try_files $uri /;

    location ~ /\.well-known/acme-challenge {
        default_type "text/plain";
        root /www/sslcert;
        try_files /$uri /;



  1. /*:80 is forwarded to /*:3000
  2. /api*:80 is forwarded to /api*:1080
  3. and everything is served over https, which is port :443

results matching ""

    No results matching ""