Caddy Server Reverse Proxy

"Caddy, sometimes clarified as the Caddy web server, is an open source, HTTP/2-enabled web server written in Go. It uses the Go standard library for its HTTP functionality. One of Caddy's most notable features is enabling HTTPS by default. It is the first general-purpose web server to do so without requiring extra configuration"

This guide is to help setup a reverse proxy for your slot with free SSL security from Lets Encrypt. You will need your own domain and it will need to be managed by Cloudflare. There are other ways to get this working but this guide will assume you own a domain and have it in your own Cloudflare account.

Installation

Downloading the server

  1. Create the needed directories

     mkdir ~/caddy
    
  2. Change to the directory

     cd ~/caddy
    
  3. Download the latest version of the Caddy Server

     wget "https://caddyserver.com/download/linux/amd64?plugins=tls.dns.cloudflare&license=personal"
    
  4. Extract the download'

     tar xzvf 'amd64?plugins=tls.dns.cloudflare&license=personal'
    
  5. Clean up

     rm -rf 'amd64?plugins=tls.dns.cloudflare&license=personal'
    

Configuration

  1. Create the configuration file

     touch ~/caddy/Caddyfile
    
  2. Edit the config

     nano ~/caddy/Caddyfile
    
  3. Copy in the example config

     **my.domain.com** {
     tls {
     dns cloudflare
     }
     gzip
     proxy /**site** localhost:**52194** {
     transparent
             }
     }
    
  4. Adust the bold values to enter your own domain/sub-domain, the site value is what needs to be entered after the domain to access the service. In this example, https://my.domain.com/site would display whatever service was running at localhost:52194 More proxy sites can be added by adding additional lines (proxy /site localhost:52194) as long as formatting is kept.

Starting the server

  1. Users do no not have root access so a few changes need to be made to ensure things can run.

  2. Setup Cloudflare details for screen to use

     nano ~/.screenrc
    
  3. Copy in the below and edit to match your own details

     setenv CLOUDFLARE_EMAIL abc
     setenv CLOUDFLARE_API_KEY 123
    
  4. Now run the server in screen, random ports have been set for your use.

     screen -dmS caddy ~/caddy/caddy -conf ~/caddy/Caddyfile -http-port 39931 -https-port 52733
    
  5. Service should be avaible at

     https://my.domain.com/site:52733