Serving static site shows a blank screen

1. Caddy version (caddy version):

v2.4.3

2. How I run Caddy:

a. System environment:

Ubuntu 18.04.1 LTS

caddy.HomeDir=/root
caddy.AppDataDir=/data/caddy
caddy.AppConfigDir=/config/caddy
caddy.ConfigAutosavePath=/config/caddy/autosave.json
caddy.Version=v2.4.3 h1:Y1FaV2N4WO3rBqxSYA8UZsZTQdN+PwcoOcAiZTM8C0I=
runtime.GOOS=linux
runtime.GOARCH=amd64
runtime.Compiler=gc
runtime.NumCPU=2
runtime.GOMAXPROCS=2
runtime.Version=go1.16.5
os.Getwd=/srv

HOSTNAME=3f103ba4b49a
CADDY_DIST_COMMIT=80870b227ded910971ecace4a0c136bf0ef46342
SHLVL=1
HOME=/root
CADDY_VERSION=v2.0.0
TERM=xterm
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
XDG_CONFIG_HOME=/config
XDG_DATA_HOME=/data
PWD=/srv

b. Command:

Runs on Docker using Portainer

c. Service/unit/compose file:


d. My complete Caddyfile or JSON config:

{
	debug
	http_port 80
	https_port 443
	# Openup the admin port to Host
	admin 0.0.0.0:2019
}


test.abc.com:443 {
	root * /home/ubuntu/static-test
	file_server browse
}

api.abc.com:443 {
	header -server
	reverse_proxy http://joven-web.local:80
} 

3. The problem I’m having:

test.abc.com is used to server static files and has index.html in the folder. Serving static files shows a blank screen

FYI, another subdomain api.abc.com uses reverse proxy and hosted on an another container. This works perfectly fine.

Log from Section 4. (below shows) content-length is 0.

4. Error messages and/or full log output:

*   Trying 52.76.158.152...
* TCP_NODELAY set
* Connected to test.abc.com (52.76.158.152) port 443 (#0)
* ALPN, offering h2
* ALPN, offering http/1.1
* successfully set certificate verify locations:
*   CAfile: /etc/ssl/cert.pem
  CApath: none
* TLSv1.2 (OUT), TLS handshake, Client hello (1):
* TLSv1.2 (IN), TLS handshake, Server hello (2):
* TLSv1.2 (IN), TLS handshake, Certificate (11):
* TLSv1.2 (IN), TLS handshake, Server key exchange (12):
* TLSv1.2 (IN), TLS handshake, Server finished (14):
* TLSv1.2 (OUT), TLS handshake, Client key exchange (16):
* TLSv1.2 (OUT), TLS change cipher, Change cipher spec (1):
* TLSv1.2 (OUT), TLS handshake, Finished (20):
* TLSv1.2 (IN), TLS change cipher, Change cipher spec (1):
* TLSv1.2 (IN), TLS handshake, Finished (20):
* SSL connection using TLSv1.2 / ECDHE-ECDSA-AES256-GCM-SHA384
* ALPN, server accepted to use h2
* Server certificate:
*  subject: CN=test.abc.com
*  start date: Aug 10 09:46:27 2021 GMT
*  expire date: Nov  8 09:46:25 2021 GMT
*  subjectAltName: host "test.abc.com" matched cert's "test.abc.com"
*  issuer: C=US; O=Let's Encrypt; CN=R3
*  SSL certificate verify ok.
* Using HTTP2, server supports multi-use
* Connection state changed (HTTP/2 confirmed)
* Copying HTTP/2 data in stream buffer to connection buffer after upgrade: len=0
* Using Stream ID: 1 (easy handle 0x7fa65a80e800)
> GET / HTTP/2
> Host: test.abc.com
> User-Agent: curl/7.64.1
> Accept: */*
> 
* Connection state changed (MAX_CONCURRENT_STREAMS == 250)!
< HTTP/2 404 
< server: Caddy
< content-length: 0
< date: Tue, 10 Aug 2021 12:19:15 GMT
< 
* Connection #0 to host test.abc.com left intact
* Closing connection 0

5. What I already tried:

  • Verified availability of index.html in the folder specified.
ubuntu@ip-172-26-11-188:~$ cd /home/ubuntu/static-test
ubuntu@ip-172-26-11-188:~/static-test$ ls -l
total 4
-rwxrwxrwx 1 ubuntu ubuntu 43 Aug 10 09:51 index.html
ubuntu@ip-172-26-11-188:~/static-test$ 
  • Caddy is in debug mode and no errors so far while accessing the site.
{"level":"debug","ts":1628597289.7657378,"logger":"http.handlers.file_server","msg":"sanitized path join","site_root":"/home/ubuntu/static-test","request_path":"/","result":"/home/ubuntu/static-test"},
{"level":"debug","ts":1628597291.1212134,"logger":"http.handlers.file_server","msg":"sanitized path join","site_root":"/home/ubuntu/static-test","request_path":"/favicon.ico","result":"/home/ubuntu/static-test/favicon.ico"},
{"level":"debug","ts":1628597529.6859283,"logger":"http.handlers.file_server","msg":"sanitized path join","site_root":"/home/ubuntu/static-test","request_path":"/index.html","result":"/home/ubuntu/static-test/index.html"},

6. Links to relevant resources:

These are already the defaults. You can remove these lines.

You can remove :443 from here. Caddy uses HTTPS by default.

This is redundant; http:// implies :80. So you can either remove :80 or remove http:// and both will work.

If it’s running in Docker, then Caddy won’t have access to files on your host machine. Docker containers are isolated from the host machine.

Did you mount /home/ubuntu/static-test somewhere inside the container?

1 Like

Thanks for your tip. Will updated those in my Caddyfile.

As you rightly pointed out, I forgot to mount the folder. Fixing it resolved the issue.

You saved hours of my time. Thanks a lot :smiley:

1 Like

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