With the https domain name enabled, use IP to access the caddy default page

The following is machine translation. My English is not very good. Please forgive me.

I deployed two HTTPS domain names using caddy, and they worked very well!

But I need to access the caddy default page by typing IP directly into the browser(Through port 80),The current situation is “IP connects directly to the server, and the browser prompts ERR_SSL_PROTOCOL_ERROR”.

How can I set up to enable IP access to successfully enter the caddy default page using http?

If the following default settings are enabled.

:80 {
root * /usr/share/caddy
file_server
}

The other two domain name websites that run perfectly will also go to the caddy default page.

What I want is
1.Access to the caddy default page through the browser IP,80 port.
2.Will not affect the normal operation of the https domain name page.

Thank you!

1 Like

Have you tried a Caddyfile like this?

:80 {
	root * /usr/share/caddy
	file_server
}

example.com {
	root * /usr/share/caddy
	file_server
}

Be aware that doing this will turn off the HTTP->HTTPS redirects that are automatically enabled for your example.com domain, since :80 will override those redirects.

If that doesn’t answer your question, I’m not sure I understand the problem.

Yes, I’ve tried. Here’s my configuration.

    :80 {
         root  * /usr/share/caddy
         file_server
    }
    example.com {
         root * /var/www/example.com
         file_server
    }

The result of this configuration is
IP → /usr/share/caddy/index.html (Correct)
example.com/usr/share/caddy/index.html (Not the right /var/www/example.com/index.html)

What I want is
IP → caddy/index.html
example.comexample.com/index.html (HTTP->HTTPS redirects)

Anyway, thank you for your reply.

If you want to retain HTTP->HTTPS redirects while configuring a :80 site, you’ll need to configure them yourself with a site block like this:

:80 {
	root  * /usr/share/caddy
	file_server
}

http://example.com {
	redir https://{host}{uri} 308
}

example.com {
	root * /var/www/example.com
	file_server
}
1 Like

Great. It solved my problem.

Thank you very much.

2 Likes

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