Caddy.json does not work

1. The problem I’m having:

I am a caddy beginner and have created a simple Caddyfile .
As expected, everything works right away:

  • the local certification is created
  • index.html is delivered at https://localhost/
  • Changes are visible immediately

My goal is to create a JSON configuration.
I checked the autosave.json and created a file caddy.json in the caddy root directory.
When I remove the Caddyfile and restart Caddy I would expect Caddy to use the caddy.json file.
Instead I receive an error 404 page not found for http and This site can’t be reached
localhost refused to connect. for https and no local certs are created.

What have I done wrong?
Thanks

2. Error messages and/or full log output:

This site can’t be reached
**localhost** refused to connect.

3. Caddy version:

Windows

v2.6.4 h1:2hwYqiRwk1tf3VruhMpLcYTg+11fCdr8S3jhNAdnPy8=

4. How I installed and ran Caddy:

a. System environment:

caddy.HomeDir=C:\Users\user
caddy.AppDataDir=C:\Users\user\AppData\Roaming\Caddy
caddy.AppConfigDir=C:\Users\user\AppData\Roaming\Caddy
caddy.ConfigAutosavePath=C:\Users\user\AppData\Roaming\Caddy\autosave.json
caddy.Version=v2.6.4 h1:2hwYqiRwk1tf3VruhMpLcYTg+11fCdr8S3jhNAdnPy8=
runtime.GOOS=windows
runtime.GOARCH=amd64
runtime.Compiler=gc
runtime.NumCPU=8
runtime.GOMAXPROCS=8
runtime.Version=go1.20.3
os.Getwd=C:\Users\user\Desktop\caddy

b. Command:

.\caddy_windows_amd64.exe run

d. My complete Caddy config:

localhost

root * ./www/html

file_server browse


{"apps":
	{"http":
		{"servers":
			{"srv0":
				{"listen":
					[":443"],
					"routes":
					[{"handle":
						[{"handler":"subroute","routes":
							[{"handle":
								[{"handler":"vars","root":"./www/html"},
									{"browse":{},
									"handler":"file_server","hide":[".\\Caddyfile"]}
						       ]}
							]}
					],
						"match":[{"host":["localhost"]}],
					"terminal":true}
				]}
			}
		}
	}
}

5. Links to relevant resources:

You need to provide the path to the config file:

$ caddy run --config caddy.json

Matt,
great, thank you very much!
Now I can move on.
Have a great day
Dave

1 Like

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