😎

Caddy: Caddyfileのインデントがスペースだと`input is not formatted`という警告が出る

2021/09/20に公開

動作環境

  • XUbuntu 18.04
  • cadddy v2.4.5

はじめに

CaddyというWebサーバを使っています。

以下のCaddyfileを使ってcaddyを起動したところ、input is not formatted with 'caddy fmt'という警告が出ました。

Caddyfile
localhost {
    file_server browse
}
$ ls
Caddyfile  hello.txt

$ sudo caddy run -config Caddyfile 
2021/09/19 23:46:39.326	INFO	using provided configuration	{"config_file": "Caddyfile", "config_adapter": ""}
2021/09/19 23:46:39.326	WARN	input is not formatted with 'caddy fmt'	{"adapter": "caddyfile", "file": "Caddyfile", "line": 2}
2021/09/19 23:46:39.327	INFO	admin	admin endpoint started	{"address": "tcp/localhost:2019", "enforce_origin": false, "origins": ["localhost:2019", "[::1]:2019", "127.0.0.1:2019"]}
2021/09/19 23:46:39.327	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}
2021/09/19 23:46:39.327	INFO	http	enabling automatic HTTP->HTTPS redirects	{"server_name": "srv0"}
2021/09/19 23:46:39.329	INFO	tls	cleaning storage unit	{"description": "FileStorage:/home/vagrant/.local/share/caddy"}
2021/09/19 23:46:39.329	INFO	tls.cache.maintenance	started background certificate maintenance	{"cache": "0xc000378d20"}
2021/09/19 23:46:39.329	INFO	tls	finished cleaning storage units
2021/09/19 23:46:39.345	INFO	pki.ca.local	root certificate is already trusted by system	{"path": "storage:pki/authorities/local/root.crt"}
2021/09/19 23:46:39.345	INFO	http	enabling automatic TLS certificate management	{"domains": ["localhost"]}
2021/09/19 23:46:39.345	WARN	tls	stapling OCSP	{"error": "no OCSP stapling for [localhost]: no OCSP server specified in certificate"}
2021/09/19 23:46:39.346	INFO	autosaved config (load with --resume flag)	{"file": "/home/vagrant/.config/caddy/autosave.json"}
2021/09/19 23:46:39.346	INFO	serving initial configuration

警告の原因

Caddyfileをcaddy fmtコマンドでフォーマットする必要がありました。

$ caddy fmt -overwrite Caddyfile

Caddyfileをフォーマットすると、以下の内容になります。

Caddyfile
localhost {
	file_server browse
}

インデントが空白からタブに変換されました。
どうやら、インデントはタブの方が推奨されるそうです。

参考サイト

GitHubで編集を提案

Discussion