caddy2 在配置上采取了动态配置站点, 并且不兼容一代配置。
语法
备注
# 备注内容
占位符
Shorthand | Replaces |
---|---|
{dir} | {http.request.uri.path.dir} |
{file} | {http.request.uri.path.file} |
{host} | {http.request.host} |
{hostport} | {http.request.hostport} |
{method} | {http.request.method} |
{path} | {http.request.uri.path} |
{query} | {http.request.uri.query} |
{remote} | {http.request.remote} |
{remote_host} | {http.request.remote.host} |
{remote_port} | {http.request.remote.port} |
{scheme} | {http.request.scheme} |
{uri} | {http.request.uri} |
{tls_cipher} | {http.request.tls.cipher_suite} |
{tls_version} | {http.request.tls.version} |
{tls_client_fingerprint} | {http.request.tls.client.fingerprint} |
{tls_client_issuer} | {http.request.tls.client.issuer} |
{tls_client_serial} | {http.request.tls.client.serial} |
{tls_client_subject} | {http.request.tls.client.subject} |
片段
# 默认跳转 https
(redirectHttps) {
@http {
scheme http
}
redir @http https://{host}{uri}
}
使用 import redirectHttps
来调用
指令
Directive | Description |
---|---|
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 |
header | Sets or removes response headers |
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...>]
}
使用时候有顺序要求
root
header
redir
rewrite
uri
try_files
basicauth
request_header
encode
templates
handle
route
respond
reverse_proxy
php_fastcgi
file_server
php
{
debug
admin off
}
(php) {
# Add trailing slash for directory requests
@canonicalPath {
file {
try_files {path}/index.php
}
not path */
}
redir @canonicalPath {path}/ 308
# If the requested file does not exist, try index files
@indexFiles {
file {
try_files {path} {path}/index.php index.php
split_path .php
}
}
try_files {path} {path}/index.php
# Proxy PHP files to the FastCGI responder
@phpFiles {
path *.php
path *.php/*
path */*.php/*
}
reverse_proxy @phpFiles 127.0.0.1:9000 {
transport fastcgi {
split .php
}
}
}
:9097 {
import php
file_server browse
}