Web Server
格式
:2015 # Host: (any), Port: 2015
localhost # Host: localhost; Port: 2015
localhost:8080 # Host: localhost; Port: 8080
example.com # Host: example.com; Ports: 80->443
http://example.com # Host: example.com; Port: 80
https://example.com # Host: example.com; Ports: 80->443
http://example.com:1234 # Host: example.com; Port: 1234
https://example.com:80 # Error! HTTPS on port 80
*.example.com # Hosts: *.example.com; Port: 2015
example.com/foo/ # Host: example.com; Ports: 80, 443; Path: /foo/
/foo/ # Host: (any), Port: 2015, Path: /foo/
Example
启动 http 和 https,访问 http 会自动转跳到 https
xp.sb { # 启动 http 和 https,访问 http 会自动转跳到 https
log access_log.log # 日志
gzip # 使用gzip压缩
proxy / http://127.0.0.1:3999 { # 路径转发
header_upstream Host {host}
header_upstream X-Real-IP {remote}
header_upstream X-Forwarded-For {remote}
header_upstream X-Forwarded-Proto {scheme}
}
}
同时启用 http 和 https 不会自动转跳
http://xp.sb https://xp.sb { # 同时启用 http 和 https 不会自动转跳
gzip
proxy / http://127.0.0.1:4999 {
header_upstream Host {host}
header_upstream X-Real-IP {remote}
header_upstream X-Forwarded-For {remote}
header_upstream X-Forwarded-Proto {scheme}
}
}
Proxy
hook.xp.sb {
proxy / http://127.0.0.1:9000 {
header_upstream Host {host}
header_upstream X-Real-IP {remote}
header_upstream X-Forwarded-For {remote}
header_upstream X-Forwarded-Proto {scheme}
}
}
http://file.xp.sb {
proxy / http://127.0.0.1:22222
}
https://file.diamondfsd.com {
root /data/file-upload # 指定静态文件根目录
}
WS
yd.xp.sb {
gzip
root /data/ydig
proxy /ws http://127.0.0.1:9001 { # 转发所有 /ws 为 websocket
websocket
}
}
GZIP
8.xp.sb {
gzip
root /data/quaver
}
File Server
No Index
# 域名:端口
http://f.xp.sb:19080 https://f.xp.sb:18080 {
root * /data/caddy # 根目录
file_server # 开启file server,如果没有index 可以加上browse参数,自动生成index页面
# 增加头参数
header {
Cache-Control no-cache
}
}
Auto Index
# 域名:端口
http://f.xp.sb:19080 https://f.xp.sb:18080 {
root * /data/caddy # 根目录
file_server browse# 开启file server,如果没有index 可以加上browse参数,自动生成index页面
# 增加头参数
header {
Cache-Control no-cache
}
}