News for hackers. Stuff that matters.
Re:The future of Nginx: Getting back to our open source roots by mholt on Tuesday August 23, 2022 @10:21PM (#32574261)
What's keeping you from using Caddy in production? We designed it for that too :D

PS. Have you seen Caddy's on-line config API? https://caddyserver.com/docs/api

Re:The future of Nginx: Getting back to our open source roots by derefr on Tuesday August 23, 2022 @10:31PM (#32574317)
Global rate-limiting bucketed by Basic-Auth-presented API key? Easy enough in Nginx; no idea how to do it with Caddy.

When people say "production", they mean things like "QoS for a shared-multitenant system, in the presence of customers with really badly tuned and spiky request workloads, whose traffic you must nevertheless mostly accept."

Re:The future of Nginx: Getting back to our open source roots by Alacart on Wednesday August 24, 2022 @12:11AM (#32574895)
As a counter point, I've been running 100k+ domains through caddy clusters with about 1tb of traffic per month (so not a ton, but not nothing). I built and manage that solo with very little maintenance or support, which I think is a testament to how reliable and performant caddy is.
Re:The future of Nginx: Getting back to our open source roots by mholt on Wednesday August 24, 2022 @12:33AM (#32575026)
Holy cow, 100k? Who are you? (Seriously) That might be the largest deployments I know about in terms of domain names.

I keep telling people "tens of thousands" when I probably should be saying "hundreds of thousands"...

Re:The future of Nginx: Getting back to our open source roots by Alacart on Wednesday August 24, 2022 @01:10AM (#32575221)
You already know me, just not under this username! I try not to put my name directly out on forums like this, but I run https://approximated.app and those 100k+ domains aren't all in one cluster, though some clusters are growing quickly and might be there in a few months. Customers paying for the clusters are generally SAAS or hosting related so they can bring a lot of user domains when they come on board and tend to grow steadily.
Re:The future of Nginx: Getting back to our open source roots by mholt on Wednesday August 24, 2022 @01:38AM (#32575312)
Ah, that's you! Thanks so much for sponsoring. Hit me up if you ever need something or would like something more/special from your sponsorship.
Re:The future of Nginx: Getting back to our open source roots by POPOSYS on Wednesday August 24, 2022 @02:09AM (#32575495)
But how do you know that it is really reliable and performant?

How do you know how many requests are silently lost?

I would like to read more about how reliability is actually measured on high-traffic sites.

Re:The future of Nginx: Getting back to our open source roots by mholt on Tuesday August 23, 2022 @11:38PM (#32574726)
If you can't already do it with the rate limit module I wrote, open an issue with your detailed requirements: https://github.com/mholt/caddy-ratelimit -- should be pretty straightforward for the most part.

> QoS for a shared-multitenant system, in the presence of customers with really badly tuned and spiky request workloads, whose traffic you must nevertheless mostly accept.

Yah, we see that sometimes. Caddy usually handles it fine, sometimes with a bit of massaging the config.

Re:The future of Nginx: Getting back to our open source roots by POPOSYS on Wednesday August 24, 2022 @02:15AM (#32575518)
We can not use Caddy as long as a reliable and battle-tested rate limit module does not exist. "Work in progress" is not something I would like to put on a production system.

It would be great if you would like to finish the work on this project and make it part of the Caddy default distribution.

Honestly I do not understand how people run high-traffic sites without rate limiting. [D]DOS attacks and other misuse (e.g. spambots etc.) are daily issues on the internet, do you just ignore that?

Re:The future of Nginx: Getting back to our open source roots by heurisko on Wednesday August 24, 2022 @03:18AM (#32575904)
Pasting a link from when we previously talked about this, for interest.

https://news.ycombinator.com/item?id=31439457

Appreciative of all the work regarding caddy, but the rate limiting seems to be chicken and egg, as few people seem to be willing to test it out in order for it to be accepted into core, and people are unwilling to test it out, because it's not in core.

It's also a blocker for me, so nginx wins by force of inertia.

Re:The future of Nginx: Getting back to our open source roots by jakearmitage on Wednesday August 24, 2022 @02:23PM (#32583661)
Same for me. If it's not on core, means devs don't want to support it, which means it is buggy, therefore not ready for production.
Re:The future of Nginx: Getting back to our open source roots by mholt on Wednesday August 24, 2022 @02:57PM (#32584105)
No; if it's not in the core, that means we don't want to bloat the code base. Caddy is extensible for very good reasons!
Re:The future of Nginx: Getting back to our open source roots by mholt on Wednesday August 24, 2022 @12:48PM (#32582133)
Happy to finish it if a company would like to sponsor that work. It works well enough for what it was originally commissioned for. It actually will probably work pretty well for you as-is. Try it!
Re:The future of Nginx: Getting back to our open source roots by cplli on Tuesday August 23, 2022 @10:52PM (#32574441)
I also only have Caddy running locally to proxy different dev environments and serve certain files, and it is an exceptional tool, but I would never deploy it in production:

1) Nginx configs are (from my experience) easier to template (in our Nomad & Consul cluster architecture) 2) From what I could gather, Nginx is more stable and performant 3) I don’t trust Caddy’s codebase security. It simply has too many dependencies, and Go makes it very easy to get into dependency hell

Honestly if 3) wouldn’t be an issue, and stability from 2) would be proven, I would probably give Caddy a try in production.

Re:The future of Nginx: Getting back to our open source roots by mholt on Tuesday August 23, 2022 @11:34PM (#32574701)
Hm, the templating thing surprises me. I'd be interested to know more about that, since Caddyfile is heavily inspired by nginx config. But for automating and scripting, I typically recommend using the JSON config.

Pro tip: Did you know you can use any config format you want to configure Caddy [1]? So if templating the Caddyfile is hard for you, use something else! You can use YAML, TOML, or even NGINX configs.

On 2, that's been pretty well debunked at this point. Caddy is written in Go, and is only a very thin wrapper over the Go standard library, which heartily powers much of Cloudflare's, Netflix's, and Google's infrastructure. Plus you gain memory safety and are exempt from a whole class of vulnerabilities with Caddy. We've seen numerous instances where Caddy has kept sites up while nginx let other sites go down, due to Caddy's resilience in the face of certificate problems, for example.

On 3, sure, I can understand that -- but this is true of any open source project. And it IS open source, so you can "own" your own code base. You're in control. And actually, Go's module proxy protects Go projects more than most C projects. Caddy's extensible architecture means that you can add all the features you need without bloating the code base.

[1]: https://caddyserver.com/docs/config-adapters

Re:The future of Nginx: Getting back to our open source roots by olau on Wednesday August 24, 2022 @02:36AM (#32575623)
On 2, are you saying that Caddy is as frugal as nginx, or were you just commenting on the stability part?

I think the ACME integration in Caddy was a really smart move, it's great to see some competition.

Re:The future of Nginx: Getting back to our open source roots by mutt2016 on Tuesday August 23, 2022 @11:00PM (#32574490)
I think it would surprise you. A lot of people seem to holdover that opinion from pre-v2, but a lot is well done. Templates are totally doable, heck you can reference exported shell vars in the config directly.
Re:The future of Nginx: Getting back to our open source roots by mholt on Tuesday August 23, 2022 @11:35PM (#32574710)
Yes! So many people apply their conceptions of Caddy v1 to Caddy 2. Thanks for the comment!
Re:The future of Nginx: Getting back to our open source roots by BrandoElFollito on Wednesday August 24, 2022 @06:13AM (#32577329)
TBH, v1 was already kilometers ahead compared to Apache or nginx for normal, casual users.

I host some stuff at home and moving from nginx to Caddy v1 was a huge breath of fresh air. V2 made the product extremely good.

I tried a bit to use the API to automate my deployments (which are, again, home deployments) but it stopped to make sense when i discovered that Caddy has the ability to read config files via wildcards.

Re:The future of Nginx: Getting back to our open source roots by aestetix on Wednesday August 24, 2022 @02:38AM (#32575635)
The primary reason I never looked seriously at Caddy is because it had an installation via a bash one liner, and refused to post a repo or a way to download specific versions. This makes maintaining many identical servers via ansible a real challenge.

To be fair, that was several years ago. But can you explain the logic behind that decision?

Re:The future of Nginx: Getting back to our open source roots by skeetmtp on Wednesday August 24, 2022 @07:28AM (#32577907)
Not the case anymore, there is a deb repo https://caddyserver.com/docs/install

I use it with ansible for 18 months with no issue

Re:The future of Nginx: Getting back to our open source roots by nicbou on Wednesday August 24, 2022 @02:48AM (#32575700)
Re:The future of Nginx: Getting back to our open source roots by francislavoie on Wednesday August 24, 2022 @02:56AM (#32575765)
That's outdated information. The cache handler plugin is ready to use: https://github.com/caddyserver/cache-handler
Re:The future of Nginx: Getting back to our open source roots by nicbou on Wednesday August 24, 2022 @05:56AM (#32577195)
Neat! I'll look into it, thanks
Re:The future of Nginx: Getting back to our open source roots by jarym on Wednesday August 24, 2022 @02:33AM (#32575610)
The docs unfortunately. It always takes longer (maybe it’s just me) to figure out how to do something non-trivial with Caddy and here both Envoy and Nginx shine.
Re:The future of Nginx: Getting back to our open source roots by francislavoie on Wednesday August 24, 2022 @02:55AM (#32575752)
Could you be more specific? What couldn't you find? If you don't let us know, we can't improve the docs.
Re:The future of Nginx: Getting back to our open source roots by jarym on Wednesday August 24, 2022 @06:48AM (#32577598)
A lot of the docs don’t explain what a module does - for example:

> dns.providers.azure wraps the provider implementation as a Caddy module.

Well great what does the provider implementation do? It’s the same for all DNS and not so useful if I’m coming from Apache or Nginx. At least explain what I’ll be able to do with this module.

From http.handlers.push:

> http.handlers.push is a middleware for manipulating the request body.

That’s a bit generic - any examples? There’s a lot of ways to modify the request body so what can I do with this?

There are 2 http.authentication.providers.jwt - both unofficial and both with 0 documentation. There has to be some standards here, why link to blank docs from your site?

All-in-all it just feels meh. I like to read docs that’ll give me the technical ins and outs of every function with some examples ideally.

Microsoft does a decent job of this as does Postgres (and others but these two come to mind immediately). Envoy is pretty nice here too and Nginx close.

Re:The future of Nginx: Getting back to our open source roots by francislavoie on Wednesday August 24, 2022 @01:05PM (#32582426)
Re "dns.providers.azure", that's a third-party module, we don't maintain that. The documentation you see in the JSON docs is auto-generated from code comments (godoc) so it's the maintainer's responsibility to write good comments that can act as documentation.

Re "http.handlers.push", fair point, that one's lacking/misleading. But this is a feature that was just added to satisfy a specific need, then fell by the wayside. Mostly because now Chrome is removing support for Server Push, so we'll need to deprecate this feature, in favor of HTTP 103 Early Hints which is the effective replacement for it.

Also, in general, we tend to spend more effort on maintaining the Caddyfile docs than the JSON docs, because the large majority of users use the Caddyfile. See https://caddyserver.com/docs/caddyfile/directives/push for the push handler, complete with examples.

Re "http.authentication.providers.jwt", well again, I think that's an issue with the module's maintainer not sufficiently using godoc comments. The maintainer registered the module under two different module paths (renamed repo) so it caused a duplicate. We'll need to manually remove the duplicate from the database, I think. It might be because there's conflicting ones that no docs are shown (cause the backend which serves the API docs is confused, I dunno, it's a bug clearly, will need to dig deeper).

Re:The future of Nginx: Getting back to our open source roots by e12e on Wednesday August 24, 2022 @07:05AM (#32577733)
Another example that was tricky in Caddy: setting up access via either whitelisted ip, or basic_auth (aka apache satisfy-any).

Useful for example for staging environments, whitelisted from certain ips, but allowing access via user-name/password from other IPs and/or the Internet.

Re:The future of Nginx: Getting back to our open source roots by francislavoie on Wednesday August 24, 2022 @01:45PM (#32583030)
Pretty easy (if I understand what you're asking for):

    @needsAuth not remote_ip private_ranges
    basicauth @needsAuth {
        user pass
    }
This uses a named matcher[0] `@needsAuth` with the `not` and `remote_ip` matchers, to match all public IP ranges (change `private_ranges` to a list of CIDRs if you prefer), then applies that request matcher to the `basicauth` handler[1], and pass in user/pass pairs to it (passwords are bcrypt hashed).

If the user fails authentication, then they won't be able to get in, as you'd expect. But users inside your allowed IP ranges will get through without basicauth.

[0]: https://caddyserver.com/docs/caddyfile/matchers

[1]: https://caddyserver.com/docs/caddyfile/directives/basicauth

Re:The future of Nginx: Getting back to our open source roots by js2 on Wednesday August 24, 2022 @12:38AM (#32575062)
Is there a Caddy equivalent to OpenResty? I use openresty as a proxy for a Python app and it's been super handy to have the lua extensibility.
Re:The future of Nginx: Getting back to our open source roots by francislavoie on Wednesday August 24, 2022 @12:45AM (#32575101)
Caddy is designed around pluggability, everything is a module. It's written in Go, so you write your middleware logic in Go. See https://caddyserver.com/docs/extending-caddy
Re:The future of Nginx: Getting back to our open source roots by Starlevel001 on Wednesday August 24, 2022 @02:23AM (#32575556)
Interesting way of saying "no"
Re:The future of Nginx: Getting back to our open source roots by francislavoie on Wednesday August 24, 2022 @02:30AM (#32575593)
Maybe you can better explain what they're asking for. Because otherwise, I find it unclear. Isn't the point of OpenResty to provide a system for building your app right inside the webserver? Because you can absolutely do that with Caddy, by writing plugins.
Re:The future of Nginx: Getting back to our open source roots by js2 on Wednesday August 24, 2022 @12:03PM (#32581288)
Here's an example of how I'm using it. Basically to log part of the response body to API requests.

    log_format  main  '$remote_addr - - [$time_local] "$request" '
                      '$status $body_bytes_sent "$host" '
                      '"$http_user_agent" $http_content_length $request_time '
                      '"$resp_body" *$connection $connection_requests';

    server {
        set $resp_body "";
        location ~ "^/api/v1/...$" {
            # Append response to resp_body until it reaches max_len.
            # - ngx.arg[1] is input chunk.
            # - ngx.arg[2] is eof flag (response is done).
            # - ngx.ctx.resp_body holds partial result between calls
            # - ngx.var.resp_body holds final result.
            # From:
            # - https://gist.github.com/morhekil/1ff0e902ed4de2adcb7a
            # - https://github.com/openresty/lua-nginx-module/
            body_filter_by_lua_block {
                local max_len = 256
                local resp_body = (ngx.ctx.resp_body or "")
                if string.len(resp_body) <= max_len then
                    resp_body = resp_body .. string.sub(ngx.arg[1], 1, max_len)
                    ngx.ctx.resp_body = string.sub(resp_body, 1, max_len)
                end
                if ngx.arg[2] then
                    ngx.var.resp_body = ngx.ctx.resp_body
                end
            }
    }
But there are many scenarios where being able to extend the HTTP server via Lua is more convenient than writing a plugin I would think?

I've also used Lua in the past with haproxy and with Redis. It's a powerful, performant, light-weight, and flexible escape hatch/extension mechanism.

Re:The future of Nginx: Getting back to our open source roots by francislavoie on Wednesday August 24, 2022 @01:50PM (#32583123)
> But there are many scenarios where being able to extend the HTTP server via Lua is more convenient than writing a plugin I would think?

Well, Caddy is written in Go, so it's only natural to write a plugin in Go. Statically compiled into your binary. We provide a tool called `xcaddy` which is used to produce builds of Caddy with any plugins you need. You just need Go installed on your system to run it, no other dependencies.

The reason why Lua is used for OpenResty is because writing plugins in C is... not fun.

You can absolutely do what you described with an HTTP handler module in Caddy. You'd just wrap the req.Body with a reader that watches the bytes as they're copied through the stream, and when you see the part you want to log, you do that.

We have a replace-response plugin which takes a similar approach, except it manipulates the response as it's being streamed back to the client. https://github.com/caddyserver/replace-response The whole plugin is just one file of Go code.

Re:The future of Nginx: Getting back to our open source roots by js2 on Wednesday August 24, 2022 @03:14PM (#32584352)
Thanks for the reply.