点击上方蓝色“飞雪无情”关注我,设个星标,第一时间看文章
在开发Caddy插件的时候,很多现成的配置可以为我们所用,这样我们插件中的某些配置就可以遵循整个Caddyfile的全局统一配置,用户体验会更好,比如使用统一的debug来控制自己开发插件的日志输出等等。
什么是全局配置
Caddyfile的全局配置和整个Caddy有关,并不局限于某个指令、请求等。在Caddy中有一些配置使用了默认的配置,但是Caddy同时也提供了全局的配置,可以让我们修改某些配置的默认值。
比如在Caddyfile中,debug默认是关闭的,我们可以通过全局配置来启用它。
{
debug
}
在整个Caddyfile的最顶部,使用一个单独的 {}
块,这个块就是自定义全局配置的地方,比如以上示例代码,我们开启了 debug
模式,这将会把所有的日志级别都设置为 debug
。
还有一个我们曾经用过的 order
其实也是一个全局配置,用它来自定义指令的顺序:
{
order hello_world last
debug
}
Caddyfile提供的全局配置有很多, order
、 debug
只是其中的两个,比如还有 http_port
用来设置http的端口,默认是80。
这里给出所有的配置列表:
{
# General Options
debug
http_port <port>
https_port <port>
order <dir1> first|last|[before|after <dir2>]
storage <module_name> {
<options...>
}
storage_clean_interval <duration>
admin off|<addr> {
origins <origins...>
enforce_origin
}
log [name] {
output <writer_module> ...
format <encoder_module> ...
level <level>
include <namespaces...>
exclude <namespaces...>
}
grace_period <duration>
# TLS Options
auto_https off|disable_redirects|ignore_loaded_certs
email <yo