Caddy 2.0 http2_error SSL握手失败,unexpected end of JSON input

浏览器打开站点突然冒出net::HTTP2_ERROR之类,站点是套了一层鹅厂的CDN。
连忙登录SSH,发现Caddy2 并没有重启过。
Caddyfile里加上

#顶部加上啊,表示开启调试日志,输出更加详细
{
debug
}

扒一扒Caddy2日志

{"level":"warn","ts":1591004115.321159,"msg":"$HOME environment variable is empty - please fix; some assets might be stored in ./caddy"}
[ERROR] xxx.cn: caching certificate after obtaining it: decoding certificate metadata: unexpected end of JSON input
{"level":"info","ts":1591004115.3211713,"logger":"watcher","msg":"watching config file for changes","config_file":"/home/xxx/caddy/Caddyfile"}
[ERROR] xxx.cn: caching certificate after obtaining it: decoding certificate metadata: unexpected end of JSON input
[ERROR] xxx.cn: caching certificate after obtaining it: decoding certificate metadata: unexpected end of JSON input
[ERROR] xxx.cn: caching certificate after obtaining it: decoding certificate metadata: unexpected end of JSON input
[ERROR] xxx.cn: caching certificate after obtaining it: decoding certificate metadata: unexpected end of JSON input
[ERROR] xxx.cn: caching certificate after obtaining it: decoding certificate metadata: unexpected end of JSON input
[ERROR] xxx.cn: caching certificate after obtaining it: decoding certificate metadata: unexpected end of JSON input
[ERROR] xxx.cn: caching certificate after obtaining it: decoding certificate metadata: unexpected end of JSON input

我突然想起来服务器前几天把默认SHELL切换为Zsh,退出SSH会话后which pm2直接搜不到了,坑爹啊
注意啦,这里讲一下,Zsh不加载 Bash默认加载的文件,也就是↓

 /etc/environment
/etc/profile
~/.bashrc
等等

Zsh默认加载↓

/etc/zsh/zshenv
/etc/zsh/zshprofile
/etc/zsh/zshrc
/etc/zsh/zshlogin
/etc/zsh/zshlogout
~/.zhrc
~/.zshenc
等等...和上面差不多,都在用户目录,不一定全都存在,不存在的话你可以手动创建

切换到Zsh后,你可以复制一份原先Bash里的配置的环境变量到Zsh默认加载的变量文件里(没错,我就是用这种方式),
另外一种方法就是在Zsh启动加载的文件里写上source /etc/profile,(注意了注意了,这个我没有实际验证过有咩有效果)

回到Caddy v2,我在Zshecho $HOME 输出/root也没毛病啊,难道是我用supervisord的原因???,果然如此。

最终解决办法

supervisord.conf

[program:caddy2]
command=/home/xxx/caddy/caddy run  --config /home/xxx/caddy/Caddyfile --watch
autorestart=true
autostart=true
startsecs=5
;**注意了就是这行解决了decoding certificate metadata: unexpected end of JSON input**
environment=HOME="/root"
directory=/home/xxx/caddy/
stdout_logfile=/tmp/caddy2.log
stdout_logfile_maxbytes=1MB
stderr_logfile=/tmp/caddy2.err.log
stderr_logfile_maxbytes=1MB

相关问题:
Caddy2 SSL握手失败,SSL握手错误?
Caddy2 http2_error怎么办?
Caddy2无法加载证书啊?
Caddy2 TLS handshake error from xxx no certificate available?
Caddy2 SSL内部错误?

Caddy v1和v2配置文件差异挺大的,改天写篇文章来详细说明一下,大家可以翻翻参照一下。

本文章原创。

你可能感兴趣的:(Caddy 2.0 http2_error SSL握手失败,unexpected end of JSON input)