How to Create Your Own Caddy Webserver in Linux
Caddy is a vibrant, easy-to-capitalize internet internet server for Linux. It jobs by centralizing the procedure of gaining landmark arrangement documents and also SSL credentials. This compose-upward will guide you wearing the procedure of installing Caddy on an Ubuntu Linux internet server. Even more, it will moreover illustrate you how to capitalize Caddy to release a simplified internet internet page as seamlessly as an SSL rescind proxy.
- Why Utilise Caddy as a Webserver?
- Placing Caddy
- Sprinting Your Initially Caddy Internet site
- Unleashing an SSL Reverse Proxy with Caddy
- Deploying Multiple Websites and also Services gaining capitalize of Caddy
Why Utilise Caddy as a Webserver?
While Nginx and also Apache are strong internet internet server daemons, they can be unwieldy and also intricate for a brand-neoteric user. Caddy cuts that intricacy by letting loose the “Caddyfile”, a single flat document with a simplified syntax that is easy to locate out even for amateurs.

Another selling time of Caddy is that it lends HTTPS for your internet internet server right out of the box. This renders it handy for users that locate prepping SSL for their site discouraging and also taxing. As such, Caddy is faultless if you’re gazing for a “no-hardship” internet internet server in Linux that’s both easy to preserve and also capitalize.
Fantastic to realize: locate out how you can recover the “404 Not Detected” error in Nginx.
Placing Caddy
The initially interfere installing Caddy in Ubuntu Linux is to administer sure that you have the devices to import its repository primes and also details:
sudo apt install curl debian-keyring debian-archive-keyring
Fetch the repository finalizing approach for Caddy from the programmer’s site:
curl -fsSL 'https://dl.cloudsmith.io/public/caddy/stable/gpg.key' | sudo gpg --dearmor -o /usr/share/keyrings/caddy-stable-archive-keyring.gpg
Download and also preserve the Caddy project’s repository document to your machine’s “sources.list.d” magazine:
curl -fsSL 'https://dl.cloudsmith.io/public/caddy/stable/debian.deb.txt' | sudo tee /etc/apt/sources.list.d/caddy.list
Reload your contraption’s proper databases by running the working together with:
sudo apt update && sudo apt upgrade
Elbowroom the Caddy unit for your contraption gaining capitalize of apt install
:
sudo apt install caddy
Sprinting Your Initially Caddy Internet site
To rushed your initially site, inflict your landmark’s origin folder in your residence magazine:
mkdir ~/my-first-website && cd ~/my-first-website
Develop an index.html document gaining capitalize of your favorite text editor:
nano ./index.html
Paste the working together with block of code inside your brand-neoteric HTML document:
</span> > >> Hello World! > > >>
Hello World! >>
Hello MakeTechEasier! > > >
Save your index.html document, after that rushed the working together with command:
caddy file-server --listen :8080
Attest that your webserver is kneading accordingly by searching to it gaining capitalize of your browser.

Unleashing a Internet site Making capitalize of Caddyfiles
While the CLI tool is exhilarating for offering simplified webpages, Caddy moreover lends an easy-to-capitalize “Caddyfile” for much more intricate setups. To embark, inflict a brand-neoteric Caddyfile under “/etc/caddy” gaining capitalize of your favorite text editor:
sudo rm /etc/caddy/Caddyfile && sudo nano /etc/caddy/Caddyfile
Paste the working together with block of code inside your brand-neoteric Caddyfile:
your-domain.com { redir https://www.{host}{uri} } www.your-domain.com { root * /var/www/html file_server }
Note: You can moreover host a LAN-single site gaining capitalize of Caddyfiles by replacing “your-domain name.com” with “localhost.”
Photocopy the index.html document from your residence magazine to your contraption’s “/var/www”:
sudo mkdir /var/www/html/ sudo cp ~/my-first-website/index.html /var/www/html
Attend your DNS registrar and also administer sure that your origin and also www subdomains has either an A or AAAA paper aiming to your machine’s IPv4 and also IPv6 addresses.

Note: You wear’t ultimatum to tweak any kind of DNS positions for LAN-single portals because Caddy will accumulate a self-signed credentials for it.
Allow the erupted-in Caddy solution on your machine:
sudo systemctl enable --now caddy
Check if your site is kneading accordingly by searching to your domain name name.

Unleashing an SSL Reverse Proxy with Caddy
Simply like Nginx and also Apache, you can moreover capitalize Caddy as a rescind proxy for an inner solution on your machine. To do this, amenable your contraption’s Caddyfile:
sudo nano /etc/caddy/Caddyfile
Paste the working together with block of code inside your Caddyfile:
your-domain.com { reverse_proxy 127.0.0.1:LOCAL-PORT }
Replace “LOCAL-PORT” with the satire of your internet entreaty. In my pill, I will readjust mine with 3001 to reroute unanimously incoming traffic to my Uptime Kuma internet server.

Save your Caddyfile, after that reload the Caddy solution to apply your brand-neoteric positions:
sudo systemctl reload caddy
Test if your rescind proxy is kneading accordingly by searching to your domain name gaining capitalize of your internet browser.

Fantastic to realize: locate out much more around internet encryption by gaining your disturbingly own SSL credentials gaining capitalize of OpenSSL.
Deploying Multiple Websites and also Services gaining capitalize of Caddy
You can moreover capitalize the disturbingly same Caddyfile to serve both portals and also proxies under the disturbingly same host. This renders it easy to juggle innumerable different options without cluttering your webserver’s config magazine.
To embark, attend Caddy’s Download internet page after that kind “caddy-dns” on the comb bar.

Appearance for the DNS use courier that steals treatment of your domain name name. In my pill, I’m gaining capitalize of DigitalOcean.
Pick your DNS use courier, after that click “Download” on the internet page’s upper right alcove. This will download a custom Caddy binary with the handy part for your DNS use courier.

Stop the Caddy solution gaining capitalize of systemctl:
sudo systemctl disable --now caddy.service
Develop a substitution of the original Caddy binary document, after that duplicate the custom binary to your “/usr/bin/” magazine.
cp /usr/bin/caddy ~/caddy.bin.bak sudo rm /usr/bin/caddy sudo cp ~/Downloads/caddy_linux_amd64_custom /usr/bin/caddy sudo chmod +x /usr/bin/caddy
Test if your custom Caddy binary is kneading accordingly by inspecting its indication:
caddy --version
Enabling Caddy SSL for Wildcard Domain names
Open your contraption’s Caddyfile gaining capitalize of your favorite text editor:
sudo nano /etc/caddy/Caddyfile
Paste the working together with block of code inside your Caddyfile:
*.your-domain.com { tls { dns digitalocean API-KEY # Replace the value of digitalocean with your DNS provider. } @www host www.your-domain.com handle @www { root * /var/www/html file_server } @subdomain host subdomain.your-domain.com handle @uptime { reverse_proxy 127.0.0.1:LOCAL-PORT } handle { abort } }
Avail an API approach from your DNS use courier. In DigitalOcean, you can administer capitalize this by visiting your DigitalOcean control panel, after that clicking API on the internet page’s disowned sidebar.

Click Amass Modern Token, after that supply the precisions for your API approach.

Photocopy your API approach, after that paste it on the “API-KEY” variable in your Caddyfile.
Individualize the Caddyfile for your certain configuration, after that preserve it.

Earn sure that your domain name name has the handy A and also AAAA records for your domain name and also subdomain.
Restart your diluted Caddy daemon to apply your brand-neoteric positions:
sudo systemctl enable --now caddy
Test if your “multi-solution” configuration jobs accordingly by opening both domains on a internet browser.

Situating out how to release simplified and also peg internet options gaining capitalize of Caddy is simply the initially interfere touring the remarkable planet of self-arranging in Linux. Dive deeper into this universe by gaining your disturbingly own e-mail pen names internet server with SimpleLogin.
Image credit: Jonathan Ybema via Unsplash and also Wikimedia Commons. With one voice fluctuations and also screenshots by Ramces Red.