How to set subpath in Caddyfile

1. Caddy version (caddy version):

v2.4.5

I want to set a subpath like in Nginx

in Nginx

server { 
  listen 443;
  server_name caddys.com;
  ssl on;
  root /root/blog;
  
  //ssl configuration

  location /books/ {
        root /root/books;
        index index.htm index.html;
    }
}

How can I do the following part in Caddyfile?

location /books/ {
    root /root/books;
    index index.htm index.html;
}

Thank you so much.

I checked help docs, I should use proxy.
Sorry to trouble.

You can use the handle_path directive for this:

example.com {
	handle_path /books* {
		root * /root/books
		file_server
	}

	handle {
		root * /root/blog
		file_server
	}
}

Next time, please completely fill out the help topic template. Don’t delete any sections. It’s important to save time, and to avoid making us make assumptions about your setup.

1 Like

I see, thank you so much.

1 Like

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