Understanding Caddy architecture

1. The problem I’m having:

Background
I am developing a website/micro service controller on AWS. I am looking for something akin to Nginx/Unit but with a newer hardware stack hence my interest in Go and Caddy. The implementation will be in docker.


Starting Simple

  • I have my first Caddy server in Docker.
  • Looking at the json schema: is there a defined schema for modules?

Reason for modules

  • I need a URL router like NGINX. I haven’t yet found out how to do this from the docs. Something akin to acme.com/ goes to Caddy web pages; acme.com/api allows me to do CRUD with POST, GET, PUT/POST and DELETE. Once routing is done I assume I will need a module to do the work other than the Caddy served web pages.
  1. Is there a GitHub repo I should look at?

Next Steps
Tomorrow I will be looking for GitHub repos to download and review. I am focusing on module integration and documentation. Any suggestions on the most important to look at?

2. Error messages and/or full log output:

This is info request ideas.  I hope you can refer to a post possibly or over me a few links.

3. Caddy version:

Caddy Version:

var/apps # caddy version
v2.6.4 h1:2hwYqiRwk1tf3VruhMpLcYTg+11fCdr8S3jhNAdnPy8=

4. How I installed and ran Caddy:

a. System environment:

Docker Mac M1 for Development AWS ECS most likely for prod. Right now looking for architectural info.

b. Command:

This is in process.  I am reviewing API calls to add the json file. Etc.  The app came up Docker run container.

c. Service/unit/compose file:

d. My complete Caddy config:

This is in design process.

5. Links to relevant resources:

I hope to have this quickly. I started working on NgOnx/Unit and now want to see how far I can push Caddy and “modules” so I don’t have to use Angular and Nginx.


Thanks so much. The software looks promising and I like developing Go.

Welcome Allen:

To truly start simple, I would recommend using Caddy without Docker. (I literally made Caddy so I wouldn’t need containers!)

There is actually a plugin by @abiosoft which can generate the JSON schema for your custom Caddy build: GitHub - abiosoft/caddy-json-schema: JSON schema generator for Caddy v2

It also integrates with editors for autocomplete which is very nice :ok_hand:

If you’re just starting, I might suggest using the Caddyfile and then playing with caddy adapt to see how it turns into JSON.

But it’s simple to do in Caddy JSON too. You just make a route that matches the requests you want to apply the route to, then the handlers to handle those requests:

What kind of work? If it’s fairly generic/general, you can probably use Caddy’s built-in functionality or an already-existing module.

If it’s custom, it’s easy to write a custom module:

Good luck! Please spend some time in the docs, you will not regret it!

And if you would like further assistance or more dedicated/private help, I’m happy to accommodate sponsors with their requirements. :+1:

Matt and I disagree on this point. Using Docker is fine, and it is simple.

You’re looking for request matchers.

The docs above are for the Caddyfile, but the same concepts apply to JSON. Like Matt said, adapt a Caddyfile to JSON to see how it looks. Easiest way to get up and running.

But consider whether you actually need JSON config. It’s probably easier not to use JSON and to stick to the Caddyfile.

1 Like

Thanks for the time. I uncovered xcaddy and will look at it.

I am going to see if I can download the docs from GitHub. I have been looking at the docs and will continue based on your suggestion.

FYI – I am very comfortable with JSON and have used it for quite a while.

I added Request Matchers to find docs on. Am I correct that once I match the URL I will need a module to execute the CRUD requests? I plan on writing that in Go.

Matt did a great job writing caddy. My Nginx/Unit stack was/is painful to get up. So yes, Caddy doesn’t need Docker on the surface. The Caddy solution is much, much smaller than my first design and is actually farther along. Thanks

HTTP routes in Caddy are a middleware pipeline. The request makes its way through the routes, executing only ones that match. Once it runs a route marked as terminal (or runs a handler that doesn’t call the next handler in the chain), it goes back up the pipeline in reverse, running any code following the next.ServeHTTP() call in each handler if any.

Trust me. If you’re a beginner with Caddy, you’ll want to start with the Caddyfile. It’ll accelerate your learning by a lot.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.