Simple basicauth setup isn't working (no proxies involved!)

I’m trying to simply protect a folder on my server with basic auth. E.g. I want everything inside https://myserver.com/dc to require a basic auth login. This is (most of) my Caddyfile:

myserver.com {
	root /var/www/blog/public
	tls ...
	gzip

	basicauth /dc test test

	git {
		repo etc etc
	}
}

However, I’ve gone in and created a file /var/www/blog/public/dc/index.html (which just contains hi), and when I visit myserver.com/dc, I can see hi - no prompt for auth or anything.

What am I getting wrong here? I’ve tried manually rebooting Caddy between changes (usually I let the github hook reload the changes). I’ve tried various ways of writing the path (e.g. basicauth test test { /dc/* }).

The correct syntax is indeed basicauth /dc test test, as per your Caddyfile.

Does it still let you though if you access your site via incognito/private session?

It does.

…but I just rebooted Caddy again manually, and now it’s prompting me for auth. So, that’s a success, but I have no idea how!

I thought that maybe the browser could have been caching a valid response, so refreshing the page didn’t ask for auth. But the first time I visited that URL, auth should have been already enabled. Hmm.

I didn’t think that the git webhook actually reloaded Caddy config? Even so, you did mention that you’ve tried manually rebooting Caddy already and previous attempts didn’t seem to take.

Ah right, in retrospect of course the webhook wouoldn’t reload the config. Silly of me! So maybe I just rebooted the server while I had a wrong path configuration. Thanks for your patience :slight_smile:

No worries, glad everything’s working out. :smiley:

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