I spent quite a bit of time getting the Nginx configuration file set up on DigitalOcean. After a LOT of work, I have arrived at the file shown below. This configuration file redirects all traffic to my secure url. In addition, all traffic is redirected to the non-www url. The first three server tags take care of that for me. I have also set up proxies for RStudio, Shiny, Jupyter Notebooks, Etherpads, and OpenRefine. Finally, I have set up the configuration to allow my own 404 page to be used across all of my site's pages.

Nginx Server Configuration

Feel free to copy, modify, and use this for your own droplets.

#============================================================================
# NGINX SERVER CONFIGURATION
# 
# All requests redirect to https://cliftonfranklund.com
# Set up reverse proxies for all my data science services
#
# Clifton Franklund, 2018, MIT
#============================================================================

server {
    listen 80;
    server_name www.cliftonfranklund.com cliftonfranklund.com;

    # redirects both http://www and http://non-www to https://non-www
    return 301 https://cliftonfranklund.com$request_uri;
}

server {
    listen 443 ssl http2;
    server_name www.cliftonfranklund.com;

    # redirects https://www to https://non-www. 
    return 301 $scheme://cliftonfranklund.com$request_uri;
}

server {
    listen 443 ssl http2 default_server;
    listen [::]:443 http2 ssl default_server;
    ssl_certificate /etc/letsencrypt/live/cliftonfranklund.com/fullchain.pem; # managed by Certbot
    ssl_certificate_key /etc/letsencrypt/live/cliftonfranklund.com/privkey.pem; # managed by Certbot
    include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
    ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot

    root /var/www;

    # Add index.php to the list if you are using PHP
    index index.html index.htm;

    server_name cliftonfranklund.com;

    location /shiny/ {
        proxy_pass http://127.0.0.1:3838/;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";
        rewrite ^(/shiny/[^/]+)$ $1/ permanent;
        proxy_intercept_errors on;
    }

    location /rstudio/ {
        proxy_pass http://127.0.0.1:8787/;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";
        proxy_intercept_errors on;
    }

    location /etherpad/ {
        proxy_pass http://127.0.0.1:9001/;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_redirect / /etherpad/;
        proxy_set_header Connection "upgrade";
        proxy_intercept_errors on;
    }

    location /openrefine/ {
        proxy_pass http://127.0.0.1:3333/;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";
        proxy_intercept_errors on;
    }

    location /jupyter/ {
        proxy_pass http://127.0.0.1:8888/jupyter/;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header Host $http_host;
        proxy_http_version 1.1;
        proxy_redirect off;
        proxy_buffering off;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";
        proxy_read_timeout 86400;
        proxy_intercept_errors on;
    }

    error_page 404 /404.html;
    location = /404.html {
        root /var/www/;
        internal;
    }

    location / {
        # First attempt to serve request as file, then
        # as directory, then fall back to displaying a 404.
        try_files $uri $uri/ =404;
    }

}

Like somethat that you read here? Feel free to share it.