以下是 Caddyfile 的標准指令。
acme_server | An embedded ACME server |
basicauth | Enforces HTTP Basic Authentication |
bind | Customize the server's socket address |
encode | Encodes (usually compresses) responses |
file_server | Serve files from disk |
handle | A mutually-exclusive group of directives |
handle_errors | Defines routes for handling errors |
handle_path | Like handle, but strips path prefix |
header | Sets or removes response headers |
import | Include snippets or files |
log | Enables access/request logging |
php_fastcgi | Serve PHP sites over FastCGI |
redir | Issues an HTTP redirect to the client |
request_header | Manipulates request headers |
respond | Writes a hard-coded response to the client |
reverse_proxy | A powerful and extensible reverse proxy |
rewrite | Rewrites the request internally |
root | Set the path to the site root |
route | A group of directives treated literally as single unit |
templates | Execute templates on the response |
tls | Customize TLS settings |
try_files | Rewrite that depends on file existence |
uri | Manipulate the URI |
指令的語法格式如下:
directive [<matcher>] <args...> { subdirective [<args...>] }
< > 中使用實際的值替換,[ ] 代表是可選的參數,... 代表一個或多個值。
大多數指令接受 [<matcher>] 來過濾請求,表示不同的請求使用不同的指令。
許多指令操縱 HTTP 處理程序鏈。這些指令的求值順序很重要,因此默認的順序被硬編碼到 Caddy 中。
root
header
redir
rewrite
uri
try_files
basicauth
request_header
encode
templates
handle
handle_path
route
respond
reverse_proxy
php_fastcgi
file_server
acme_server
如果需要自定義順序,可以使用 order 全局選項,或者 route 指令。