Caddyfile
最后更新于:2022-04-02 02:55:37
[TOC]
## 概述
- Caddy 通过配置Caddyfile
- 无法支持使用 0.0.0.0:8080 的写法, 只能写具体的ip 192.168.0.151:8080
![](https://caddyserver.com/resources/images/caddyfile-visual.png)
## 语法
### 单站点 / 多站点
单站点
```
localhost
encode zstd gzip
templates
file_server browse
```
多站点
```
localhost {
encode zstd gzip
templates
file_server browse
}
...
```
### 只填 `:port` 则只支持http
```
:8080{
...
}
```
### 只填 ip/域名 则http跳转到 https
并且 无法访问 http
如
```
192.168.0.151:8080{
...
}
```
如果只需要 http 则在网址前显示添加 http
如
```
http://192.168.0.151:8080{
...
}
```
### 多站点指向同地址
```
:8080, :8081 {
...
}
```
### 使用环境变量
```
export SITE_ADDRESS=localhost:9055
```
使用
```
{$SITE_ADDRESS}
file_server
// 解析
localhost:9055
file_server
```
### 占位符
| Shorthand | Replaces |
| --- | --- |
| `{dir}` | `{http.request.uri.path.dir}` |
| `{file}` | `{http.request.uri.path.file}` |
| `{header.*}` | `{http.request.header.*}` |
| `{host}` | `{http.request.host}` |
| `{labels.*}` | `{http.request.host.labels.*}` |
| `{hostport}` | `{http.request.hostport}` |
| `{port}` | `{http.request.port}` |
| `{method}` | `{http.request.method}` |
| `{path}` | `{http.request.uri.path}` |
| `{path.*}` | `{http.request.uri.path.*}` |
| `{query}` | `{http.request.uri.query}` |
| `{query.*}` | `{http.request.uri.query.*}` |
| `{re.*.*}` | `{http.regexp.*.*}` |
| `{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}` |
### 支持 php
';