How to show up the correct index.html using caddy2

1. Caddy version (caddy version):

v2.4.3 h1:Y1FaV2N4WO3rBqxSYA8UZsZTQdN+PwcoOcAiZTM8C0I=

2. How I run Caddy:

#!/bin/bash


/Users/jianfei/Documents/418-weBook/macOS-caddy/caddy_darwin_amd64 start -watch -config /Users/jianfei/Documents/418-weBook/macOS-caddy/caddy-macOS.conf -adapter caddyfile

a. System environment:

macOS Big Sur, 11.4

b. Command:

#!/bin/bash


/Users/jianfei/Documents/418-weBook/macOS-caddy/caddy_darwin_amd64 start -watch -config /Users/jianfei/Documents/418-weBook/macOS-caddy/caddy-macOS.conf -adapter caddyfile

c. Service/unit/compose file:

Paste full file contents here.
Make sure backticks stay on their own lines,
and the post looks nice in the preview pane.

d. My complete Caddyfile or JSON config:

localhost:8020 {
	tls internal

	encode gzip

	log {
		output file /Users/jianfei/Documents/418-weBook/log/access-20210709.log
	}

	root * /Users/jianfei/Documents/418-weBook/webook-tree

	# index { index.html }
	try_files {/Users/jianfei/Documents/418-weBook/webook-tree/} {index}.html
}

3. The problem I’m having:

I can see a white screen showing up “Client sent an HTTP request to an HTTPS server.” if I type http://localhost:8020

while I can see a somewhat black screen showing up “404 page not found” if I type http://localhost:2019

In a word, I can’t judge which is the correct port for my portable web server.

And I want to know, how to correctly specify the proper index.html in caddy file?

4. Error messages and/or full log output:


2021/07/09 16:24:37.081	info	http.log.access.log0	handled request	{"request": {"remote_addr": "127.0.0.1:54451", "proto": "HTTP/2.0", "method": "GET", "host": "localhost:8020", "uri": "/", "headers": {"User-Agent": ["Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/14.1.1 Safari/605.1.15"], "Accept": ["text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"], "Accept-Language": ["en-us"], "Accept-Encoding": ["gzip, deflate, br"]}, "tls": {"resumed": false, "version": 772, "cipher_suite": 4865, "proto": "h2", "proto_mutual": true, "server_name": "localhost"}}, "common_log": "127.0.0.1 - - [10/Jul/2021:00:24:37 +0800] \"GET / HTTP/2.0\" 0 0", "duration": 0.000082805, "size": 0, "status": 0, "resp_headers": {"Server": ["Caddy"]}}
2021/07/09 16:24:37.098	info	http.log.access.log0	handled request	{"request": {"remote_addr": "127.0.0.1:54452", "proto": "HTTP/2.0", "method": "GET", "host": "localhost:8020", "uri": "/favicon.ico", "headers": {"Accept": ["*/*"], "Accept-Encoding": ["gzip, deflate, br"], "User-Agent": ["Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/14.1.1 Safari/605.1.15"], "Accept-Language": ["en-us"], "Referer": ["https://localhost:8020/"]}, "tls": {"resumed": false, "version": 772, "cipher_suite": 4865, "proto": "h2", "proto_mutual": true, "server_name": "localhost"}}, "common_log": "127.0.0.1 - - [10/Jul/2021:00:24:37 +0800] \"GET /favicon.ico HTTP/2.0\" 0 0", "duration": 0.000027059, "size": 0, "status": 0, "resp_headers": {"Server": ["Caddy"]}}
2021/07/09 16:29:21.626	info	http.log.access.log0	handled request	{"request": {"remote_addr": "127.0.0.1:54575", "proto": "HTTP/2.0", "method": "GET", "host": "localhost:8020", "uri": "/", "headers": {"Accept-Language": ["en-us"], "Accept-Encoding": ["gzip, deflate, br"], "User-Agent": ["Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/14.1.1 Safari/605.1.15"], "Accept": ["text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"]}, "tls": {"resumed": false, "version": 772, "cipher_suite": 4865, "proto": "h2", "proto_mutual": true, "server_name": "localhost"}}, "common_log": "127.0.0.1 - - [10/Jul/2021:00:29:21 +0800] \"GET / HTTP/2.0\" 0 0", "duration": 0.000214201, "size": 0, "status": 0, "resp_headers": {"Server": ["Caddy"]}}
2021/07/09 16:29:32.791	info	http.log.access.log0	handled request	{"request": {"remote_addr": "127.0.0.1:54596", "proto": "HTTP/2.0", "method": "GET", "host": "localhost:8020", "uri": "/", "headers": {"User-Agent": ["Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/14.1.1 Safari/605.1.15"], "Accept": ["text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"], "Accept-Language": ["en-us"], "Accept-Encoding": ["gzip, deflate, br"]}, "tls": {"resumed": false, "version": 772, "cipher_suite": 4865, "proto": "h2", "proto_mutual": true, "server_name": "localhost"}}, "common_log": "127.0.0.1 - - [10/Jul/2021:00:29:32 +0800] \"GET / HTTP/2.0\" 0 0", "duration": 0.000088101, "size": 0, "status": 0, "resp_headers": {"Server": ["Caddy"]}}
2021/07/09 16:30:03.040	info	http.log.access.log0	handled request	{"request": {"remote_addr": "[::1]:54608", "proto": "HTTP/2.0", "method": "GET", "host": "localhost:8020", "uri": "/", "headers": {"Sec-Ch-Ua-Mobile": ["?0"], "Dnt": ["1"], "User-Agent": ["Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.114 Safari/537.36"], "Accept": ["text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9"], "Sec-Fetch-Site": ["none"], "Sec-Fetch-User": ["?1"], "Sec-Fetch-Dest": ["document"], "Sec-Ch-Ua": ["\" Not;A Brand\";v=\"99\", \"Google Chrome\";v=\"91\", \"Chromium\";v=\"91\""], "Upgrade-Insecure-Requests": ["1"], "Sec-Fetch-Mode": ["navigate"], "Accept-Encoding": ["gzip, deflate, br"], "Accept-Language": ["zh-CN,zh;q=0.9,en-US;q=0.8,en;q=0.7,zh-TW;q=0.6,ja;q=0.5"]}, "tls": {"resumed": false, "version": 772, "cipher_suite": 4865, "proto": "h2", "proto_mutual": true, "server_name": "localhost"}}, "common_log": "::1 - - [10/Jul/2021:00:30:03 +0800] \"GET / HTTP/2.0\" 0 0", "duration": 0.000111741, "size": 0, "status": 0, "resp_headers": {"Server": ["Caddy"]}}
2021/07/09 16:30:03.153	info	http.log.access.log0	handled request	{"request": {"remote_addr": "[::1]:54608", "proto": "HTTP/2.0", "method": "GET", "host": "localhost:8020", "uri": "/favicon.ico", "headers": {"Sec-Fetch-Mode": ["no-cors"], "Sec-Fetch-Dest": ["image"], "Referer": ["https://localhost:8020/"], "Sec-Ch-Ua": ["\" Not;A Brand\";v=\"99\", \"Google Chrome\";v=\"91\", \"Chromium\";v=\"91\""], "Dnt": ["1"], "Accept": ["image/avif,image/webp,image/apng,image/svg+xml,image/*,*/*;q=0.8"], "Accept-Encoding": ["gzip, deflate, br"], "Accept-Language": ["zh-CN,zh;q=0.9,en-US;q=0.8,en;q=0.7,zh-TW;q=0.6,ja;q=0.5"], "Sec-Ch-Ua-Mobile": ["?0"], "User-Agent": ["Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.114 Safari/537.36"], "Sec-Fetch-Site": ["same-origin"]}, "tls": {"resumed": false, "version": 772, "cipher_suite": 4865, "proto": "h2", "proto_mutual": true, "server_name": "localhost"}}, "common_log": "::1 - - [10/Jul/2021:00:30:03 +0800] \"GET /favicon.ico HTTP/2.0\" 0 0", "duration": 0.000105456, "size": 0, "status": 0, "resp_headers": {"Server": ["Caddy"]}}
2021/07/09 16:30:46.582	info	http.log.access.log0	handled request	{"request": {"remote_addr": "127.0.0.1:54616", "proto": "HTTP/2.0", "method": "GET", "host": "localhost:8020", "uri": "/", "headers": {"User-Agent": ["Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/14.1.1 Safari/605.1.15"], "Accept": ["text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"], "Accept-Language": ["en-us"], "Accept-Encoding": ["gzip, deflate, br"]}, "tls": {"resumed": false, "version": 772, "cipher_suite": 4865, "proto": "h2", "proto_mutual": true, "server_name": "localhost"}}, "common_log": "127.0.0.1 - - [10/Jul/2021:00:30:46 +0800] \"GET / HTTP/2.0\" 0 0", "duration": 0.000108172, "size": 0, "status": 0, "resp_headers": {"Server": ["Caddy"]}}
2021/07/09 16:30:47.993	info	http.log.access.log0	handled request	{"request": {"remote_addr": "127.0.0.1:54616", "proto": "HTTP/2.0", "method": "GET", "host": "localhost:8020", "uri": "/", "headers": {"Accept-Encoding": ["gzip, deflate, br"], "User-Agent": ["Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/14.1.1 Safari/605.1.15"], "Accept": ["text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"], "Accept-Language": ["en-us"]}, "tls": {"resumed": false, "version": 772, "cipher_suite": 4865, "proto": "h2", "proto_mutual": true, "server_name": "localhost"}}, "common_log": "127.0.0.1 - - [10/Jul/2021:00:30:47 +0800] \"GET / HTTP/2.0\" 0 0", "duration": 0.000183353, "size": 0, "status": 0, "resp_headers": {"Server": ["Caddy"]}}
2021/07/09 16:30:51.958	info	http.log.access.log0	handled request	{"request": {"remote_addr": "127.0.0.1:54617", "proto": "HTTP/2.0", "method": "GET", "host": "localhost:8020", "uri": "/", "headers": {"User-Agent": ["Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/14.1.1 Safari/605.1.15"], "Accept": ["text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"], "Accept-Language": ["en-us"], "Accept-Encoding": ["gzip, deflate, br"]}, "tls": {"resumed": false, "version": 772, "cipher_suite": 4865, "proto": "h2", "proto_mutual": true, "server_name": "localhost"}}, "common_log": "127.0.0.1 - - [10/Jul/2021:00:30:51 +0800] \"GET / HTTP/2.0\" 0 0", "duration": 0.000111705, "size": 0, "status": 0, "resp_headers": {"Server": ["Caddy"]}}
2021/07/09 17:45:07.106	info	http.log.access.log0	handled request	{"request": {"remote_addr": "127.0.0.1:56836", "proto": "HTTP/2.0", "method": "GET", "host": "localhost:8020", "uri": "/", "headers": {"User-Agent": ["Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/14.1.1 Safari/605.1.15"], "Accept": ["text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"], "Accept-Language": ["en-us"], "Accept-Encoding": ["gzip, deflate, br"]}, "tls": {"resumed": false, "version": 772, "cipher_suite": 4865, "proto": "h2", "proto_mutual": true, "server_name": "localhost"}}, "common_log": "127.0.0.1 - - [10/Jul/2021:01:45:07 +0800] \"GET / HTTP/2.0\" 0 0", "duration": 0.000132858, "size": 0, "status": 0, "resp_headers": {"Server": ["Caddy"]}}

5. What I already tried:

I have tried to search by Google or in the official site of caddy, but no accurate answer to my puzzle.

6. Links to relevant resources:

No. Thank you!

the code of index.html

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8" />
    <meta http-equiv="x-ua-compatible" content="ie=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1" />

    <title>剑飞叔叔的小屋</title>
    <link rel="stylesheet" href="css/main.css" />
    <link rel="icon" href="images/favicon.png" />
  </head>

  <body>
    <script src="js/scripts.js"></script>
    我的软件之道。
    
  </body>
</html>

You’re missing the file_server directive, which is what actually does the work of serving static files.

Caddy defaults to HTTPS by default. If you want to use HTTP, then specify http:// in front of the site address. You specified tls internal though, so that’s explicitly telling it to server HTTPS. You need to connect with https:// with your client, not http:// when connecting on that port.

Thank you! It works

1 Like

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