Site served by Caddy looks different to my HTML when open from disk

1. Caddy version (caddy version):

2.2.1-r1 (devel)

2. How I run Caddy:

a. System environment:

Alpine Linux 3.12
Kernel 5.4.72-0-virt
OpenRC

b. Command:

This comes from my /etc/conf.d/caddy

caddy_opts="--config /etc/caddy/Caddyfile --adapter caddyfile"

c. Service/unit/compose file:

/etc/init.d/caddy

#!/sbin/openrc-run
supervisor=supervise-daemon

name="Caddy web server"
description="Fast, multi-platform web server with automatic HTTPS"
description_checkconfig="Check configuration"
description_reload="Reload configuration without downtime"

command=/usr/sbin/caddy
command_args="run $caddy_opts"
command_user=caddy:caddy
extra_commands="checkconfig"
extra_started_commands="reload"

depend() {
	need net localmount
	after firewall
}

checkconfig() {
	ebegin "Checking configuration for $name"
	su ${command_user%:*} -s /bin/sh -c "$command validate $caddy_opts"
	eend $?
}

reload() {
	ebegin "Reloading $name"
	su ${command_user%:*} -s /bin/sh -c "$command reload $caddy_opts"
	eend $?
}

stop_pre() {
	if [ "$RC_CMD" = restart ]; then
		checkconfig || return $?
	fi
}

d. My complete Caddyfile or JSON config:

# Caddy's configuration file
# see: https://caddyserver.com/docs/caddyfile

localhost, 127.0.0.1, httpd1.local, 192.168.0.240 {
	root *  /var/www
}

3. The problem I’m having:

When accessing the site served by Caddy it differs from the one displayed when open from a hardrive.
Side by side comparison below.

4. Error messages and/or full log output:

No error messages. Here’s the output after

 * Checking configuration for Caddy web server ...2020/11/16 18:29:41.794	INFO	using provided configuration	{"config_file": "/etc/caddy/Caddyfile", "config_adapter": "caddyfile"}
2020/11/16 18:29:41.795	INFO	http	server is listening only on the HTTPS port but has no TLS connection policies; adding one to enable TLS	{"server_name": "srv0", "https_port": 443}
2020/11/16 18:29:41.795	INFO	http	enabling automatic HTTP->HTTPS redirects	{"server_name": "srv0"}
2020/11/16 18:29:41.810	INFO	tls	setting internal issuer for automation policy that has only internal subjects but no issuer configured{"subjects": ["localhost", "127.0.0.1", "httpd1.local", "192.168.0.240"]}
2020/11/16 18:29:41.811	INFO	tls.cache.maintenance	started background certificate maintenance	{"cache": "0xc0002563f0"}
2020/11/16 18:29:41.811	INFO	tls.cache.maintenance	stopped background certificate maintenance	{"cache": "0xc0002563f0"}
Valid configuration
 [ ok ]
 * Stopping Caddy web server ... [ ok ]
 * Starting Caddy web server ... [ ok ]

5. What I already tried:

Tried adding

file_server

to the Caddyfile

6. Links to relevant resources:

Website isn’t the main purpose here, so I created it using Canva.
Link here

Il it possible to share the content of the HTML file and the site directory layout? I’d be surprised if it’s an issue with Caddy because Caddy is just copying the bytes.

Hi Mohammed,
As Canva doesn’t allow to simply download HTML I have done it with Firefox’s Save As, so my /var/www contains index.html and index_files folder.
Here’s the HTML source

Where did you add it though? Needs to be inside the site block (e.g. just below root)

file_server is required to serve files in Caddy v2, it was implicit in Caddy v1.

You should right-click on the rendered page and click View Page Source, and compare the two.

Caddy’s file_server doesn’t modify HTML content by default, so you must have something else going on. Probably a CSS file not being loaded or something. Check your browser debugger’s Network tab to see if everything loaded properly.

Blockquote
Where did you add it though? Needs to be inside the site block (e.g. just below root)

That’s exactly where I’ve added it.

To be honest, I do believe as well it must be HTML fault, but still it is rater awkward that the very same file is displayed differently in the same browser, at the same time.
Quick look at the page source, they identical. As it is generated by Canva, there’s a lot of weirdly named divs. I’ve used it to save time, having to dwell on that for this long I think I’ll be better of writing my own HTML.
Thank you guys.

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