Ngx_http_random_index_module Caddy alternative

When using Nginx I sometimes make use of the ngx_http_random_index_module, I’m wondering if there’s anything like this for Caddy2?

Interesting, I have never heard of this before.

A plugin could definitely do this, or we could even probably do this with the file matcher – like a random policy or something.

What’s the use case for this?

1 Like

Yeah I agree that could work. In theory, it would look like this:

root * /path/to/webroot

@random {
	path /random/
	file {
		try_policy random
rewrite @random {http.matchers.file.relative}


I’d like to understand this too, before we spend any time working on this.

Please explain how you’d use this and why.

1 Like

My (alas, only and slightly contrived) example is having a route which serves a random image from a directory I own as part of a random daily image wallpaper rotator.

In the meantime I’ve written a simple server in rust and reverse_proxy /random to the servers port, however something native to Caddy would be nice.

I plan on writing a plugin in Go to achieve this, so I’ll update this thread if I get round to it.


Would love to see it!

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