Skip to content

Learning project for the caddy server

License

Notifications You must be signed in to change notification settings

feedm3/learning-caddy

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

22 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Caddy tutorial

This repo is about learning Caddy web server.

The official documentation can be found here: https://caddyserver.com/docs

Why Caddy

  • easy to setup and use
  • https by default with no conguration needed (from let's encrypt)
  • HTTP/2, IPv6, Markdown, WebSockets, gzip, basic auth, templates and more right out of the box
  • build for designer, bloggers and developers

Setup

  1. Download Caddy: https://caddyserver.com/download

  2. Create a config which is namend Caddyfile and add the following minimal config

    localhost:8080 {
        root www
    }
    
  3. Put your web assets into the www folder

  4. Start Caddy with caddy. If your config file is not in the same directory as you are you can use it via the conf option like -conf="DIR_TO_CONF/Caddyfile"

To start the example servers within this repo (configuration and caddy itself) hit

# Mac
./bin/mac/caddy

# Windwos
bin\win64\caddy.exe

# Linux
./bin/linux64/caddy

Feature deep-dive

All configuration is made in the Caddyfile. There are a lot of build in features but some need to be added to the binary. You have to re-download Caddy with the additional features if you want to use one of them, it cant be added afterwards.

The following features are all build-in. If a feature must be added to the binary it is marked with an A in the documentation.

Ext

Docs

Ext allows you to make clearer URLs by allowing to leave out the file extension in the URL

ext .html .md

With the example above the user can now go to the hello.html file with either /hello.html or /hello.

Errors

Docs

You can map HTTP errors to specific pages

errors {
    404 notfound.html
    503 serviceunavail.html
}

Markdown

Docs

Caddy can render markdown files out of the box

markdown

The markdown files can also be served with custom css and js.

basicauth

Docs

You can protect files and directories with simple basic auth

basicauth user password {
    /secret
}

Logs

Docs

Caddy will log every request when you add the log tag.

log / logs/access.log

Theres an easy syntax to format the logs to your needs.

gzip

Docs

gzip enabled gzip support if the client supprots it.

gzip

Proxy

Docs

Caddy can server as proxy

proxy /hypem hypem.com:80 {
    without /hypem
}

This will proxy all /hypem requests to hypem.com. If we would not add the without tag the request would be proxied with the host in the URL. Example URL: http://localhost:8080/hypem/playlist/popular/3day/json/1/data.js

Load balancer

Docs

Load balancer is part of the proxy feature. There are some policy features available as well as health checks to only server to working servers.

localhost:2016 {
    proxy / localhost:8080 localhost:8081 {
        policy random
    }
}

Further reading

Made with ❤️ at SinnerSchrader

About

Learning project for the caddy server

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published