Password Protect Directory

How to password protect a directory on Caddy 2. As for example, if I have to password protect phpMyAdmin located at:


Whereas, my website root directory is located at:



The basicauth directive is made exactly for that!

Yeh I seen that but I was not able to make it work. Can I get a working example please.

There are examples right at the bottom of that documentation page.

What have you tried? What’s your current Caddyfile?

Bob can access protected /secret/* resources with password “hiccup”. Thats fine!

But, Where there is hiccup in:

basicauth /secret/* {

How to generate that encrypted password:


and use. That I didn’t understand!

I mean what I have to command on SSH? Like:

caddy hash-password hiccup

What’s the right one?

Okay got that:
caddy hash-password --plaintext hiccup --algorithm scrypt --salt base-64

The documentation for caddy hash-password ist here:

1 Like

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