Pagi ini ada terbesit sebuah ide supaya tidak usah repot memperpanjang certificate Letsencrypt setiap 3 bulan, karena pasti akan ada waktunya lupa 😀
Salah satu solusinya adalah dengan mempergunakan web server Caddy, yang secara otomatis akan memperpanjang Certificatenya.
Hal ini kepikiran karena salah satu situs monitoring yang sudah lama saya buat memakai NodeJS ternyata SSLnya masih aktif, tidak expired, dan ternyata setupnya mempergunakan Caddy.
Berikut adalah langkah-langkah instalasi Caddy di Debian 11 :
1 2 3 4 5 |
sudo apt install -y debian-keyring debian-archive-keyring apt-transport-https curl curl -1sLf 'https://dl.cloudsmith.io/public/caddy/stable/gpg.key' | sudo gpg --dearmor -o /usr/share/keyrings/caddy-stable-archive-keyring.gpg curl -1sLf 'https://dl.cloudsmith.io/public/caddy/stable/debian.deb.txt' | sudo tee /etc/apt/sources.list.d/caddy-stable.list sudo apt update sudo apt install caddy |
Default Caddy adalah memproses ke https, jadi berikut contoh untuk web statik dan juga jika memakai proxy :
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# The Caddyfile is an easy way to configure your Caddy web server. # # Unless the file starts with a global options block, the first # uncommented line is always the address of your site. # # To use your own domain name (with automatic HTTPS), first make # sure your domain's A/AAAA DNS records are properly pointed to # this machine's public IP, then replace ":80" below with your # domain name. #:80 { # # Set this path to your site's directory. # root * /usr/share/caddy # # Enable the static file server. # file_server # Another common task is to set up a reverse proxy: # reverse_proxy localhost:8080 # Or serve a PHP site through php-fpm: # php_fastcgi localhost:9000 #} # Refer to the Caddy docs for more information: # https://caddyserver.com/docs/caddyfile # php_fastcgi unix//var/run/php/php7.2-fpm.sock # redirect request yang memakai www www.erawanarifnugroho.com { redir https://erawanarifnugroho.com{uri} } # redirect request yang eror ke file index.html https://erawanarifnugroho.com { root * /home/erawanarifn/http/hosts/erawanarifnugroho.com encode gzip zstd handle_errors { redir * /index.html file_server } file_server } # Sebagai proxy untuk Ghost https://arsip.my.id { reverse_proxy 127.0.0.1:3333 } |
Karena web erawanarifnugroho.com hanya memakai file html, maka cukup seperti itu. Tapi kalau memakai php, tinggal uncomment saja.
Sederhana ya?
Barangkali muncul eror tcp bind denied di port 80, coba jalankan perintah ini :
1 |
sudo setcap 'cap_net_bind_service=+ep' /usr/bin/caddy |