静态托管
通过 HTTP 提供一目录的静态文件(HTML、CSS、JS、图片)—— 带压缩,无需应用 服务器。
把文件放进一个目录,用 file_server 指向一个站点:
static.example.com { root /var/www/html file_server}root 设置目录;file_server 提供它。像 ./public 这样的相对路径从 raddex
的工作目录解析。
要发送压缩响应,加 encode —— 客户端也支持的第一个算法胜出。可使用
gzip、zstd 与 Brotli(br):
static.example.com { root /var/www/html file_server encode br zstd gzip}协商如何工作、如何选择算法,见压缩指南。
raddex check -c Raddexfileraddex run -c Raddexfile你能得到什么
Section titled “你能得到什么”curl -H 'Host: static.example.com' http://127.0.0.1:8090/ # index.htmlcurl -H 'Host: static.example.com' http://127.0.0.1:8090/app.js # 一个文件curl -H 'Host: static.example.com' -H 'Accept-Encoding: gzip' \ http://127.0.0.1:8090/app.js -sD - -o /dev/null # Content-Encoding: gzip可依赖的行为:
- 目录提供其
index.html——/映射到index.html。 - 仅允许
GET与HEAD;其他方法被拒绝。 - 路径穿越被阻止 ——
/../etc/passwd返回404,而不是你的文件。 encode同样压缩file_server的响应,遵循客户端的Accept-Encoding。file_server提供root+ 完整请求路径,含任何handle前缀(见下)。
用 handle 在某个路径下提供静态文件,其余代理给应用:
example.com { handle /static/* { root /var/www/html file_server encode zstd gzip }
reverse_proxy 127.0.0.1:8080}这里 /static/app.js 映射到 /var/www/html/static/app.js —— handle
前缀保留在路径中。