Some help in replicating an nginx config needed

Hi everyone,
I’ve been using Caddy in front of nginx for a while now, mainly because it was impossible to replicate the behaviour at all. As I understand it, this is now possible, so I am wondering if there’s a clean way to do the following:

location ~ ^(/Video/|/Music/|/Photos/|/Text/|/Code/) {
    autoindex on;
    deny all;
    root   /stuff;

location / {
    autoindex off;
    allow all;
    root   /stuff;
    index  index.html index.htm;

Basically, is there a way for me to use the same config as above without having to repeat the first part once per URL? The only way I see in the docs to do it is to add five sections with the exact same contents, which is rather unwieldy.

I ended up figuring it out when I tried a different way (without subpaths). Here it is: {
    root /stuff

    ipfilter /Video /Music /Photos /Text /Code {
        rule allow
        ip   192.168.0

    browse /Video
    browse /Music
    browse /Photos
    browse /Text
    browse /Code
1 Like

Hey @Stavros, thank you for posting! You can use three backticks (`) (not tilde, ~) to enclose your Caddyfile and it will be properly formatted. (Feel free to edit your post so it is formatted well. Thanks!)

Oops, thanks Matt, I didn’t even look at the preview for the second post.

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