首页/新闻资讯/正文详情

caddy配置文件Caddyfile示例

发布时间:2026/9/24 14:01:04 来源:云帆数科 栏目:资讯中心
caddy配置文件Caddyfile示例
{ # 这块是全局配置 # http不要自动转跳https auto_https disable_redirects # 内部私有证书,不要自动安装到certs系统目录里 skip_install_trust # 在线核对证书状态间隔时间, ocsp_interval 12h # 全局监听配置 #servers { # http请求头最大字节大小 # max_header_size 5MB # # tcp keepalive保活时间 # keepalive_interval 30s # listener_wrappers { # # http自动转跳https # http_redirect # tls # } #} # 全局日志 log { level ERROR # based on hostname # output file /var/log/caddy/{host}.log format json } # 全局设置信任来自 Cloudflare 节点的请求头 servers { trusted_proxies static 173.245.48.0/20 103.21.244.0/22 103.22.200.0/22 103.31.4.0/22 141.101.64.0/18 108.162.192.0/18 190.93.240.0/20 188.114.96.0/20 197.234.240.0/22 198.41.128.0/17 162.158.0.0/15 104.16.0.0/13 104.24.0.0/14 172.64.0.0/13 131.0.72.0/22 } } # ------ # 举例使用 import block__handle_check_slash_end_args /test (block__handle_check_slash_end_args) { #route { # noSlash { # path_regexp [^/]$ # Match paths that do not end with a slash # } # redir noSlash {http.request.scheme}://{http.request.host}{http.request.uri}/ 302 # } append_slash { path_regexp /({args[0]}|{args[1]}|{args[2]}|{args[3]}|{args[4]}|{args[5]}|{args[6]}|{args[7]}|{args[8]}|{args[9]})[^/]*$ } redir append_slash {path} {path}/ 302 } # 举例使用 import block__sub_header (block__sub_header) { header { -server server IIS/10.0 x-aspnet-version 9.0 x-server-version 9.0 frame-options SAMRORIGIN -proxy-connection } } # 举例使用 import block__logger_args /tmp/logs/caddylogs/xxx.log (block__logger_args) { log { output file /home/datum/logs/caddylogs/{args[0]}.log { roll_size 1gb roll_uncompressed } } } # 举例使用 import block__cors (block__cors) { route { CheckOptions { method OPTIONS } # 跨域预请求响应 respond CheckOptions 200 { #header Access-Control-Allow-Headers * #这个有问题,不能是通配符 #header Access-Control-Allow-Headers X-XSRF-TOKEN,XSRF-TOKEN,language,token,DNT,X-Mx-ReqToken,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Authorization header Access-Control-Allow-Methods GET,POST,PUT,OPTIONS header Access-Control-Allow-Origin {http.request.header.Origin} header Access-Control-Allow-Headers {http.request.header.Access-Control-Request-Headers} header Access-Control-Allow-Credentials true #respond 200 } notOptions { not method OPTIONS } # 默认常规请求方式响应(非options) header notOptions { # Echo Access-Control-Allow-Methods GET, POST, PUT, OPTIONS Access-Control-Allow-Origin {http.request.header.Origin} Access-Control-Allow-Headers {http.request.header.Access-Control-Request-Headers} Access-Control-Allow-Credentials true } } } # 举例使用 import block__proxy_upstream_cors_headers_strip (block__proxy_upstream_cors_headers_strip) { #请求上游重写替换请求头,Strip header_up Access-Control-Allow-Origin header_up Access-Control-Allow-Methods header_up Access-Control-Allow-Headers # 响应给下游(浏览器)的响应头maybe duplicated header_down Access-Control-Allow-Methods GET,POST,PUT,OPTIONS header_down Access-Control-Allow-Origin {http.request.header.Origin} header_down Access-Control-Allow-Headers {http.request.header.Access-Control-Request-Headers} header_down Access-Control-Allow-Credentials true } # 举例使用 import block__html_no_cache (block__html_no_cache) { # Apply no-cache headers only to .html files htmlFiles { path *.html } header htmlFiles { Cache-Control no-cache, no-store, must-revalidate, max-age0 Pragma no-cache Expires 0 } } # 代码块使用举例:import block__http2https (block__http2https) { CheckHttp { protocol http } redir CheckHttp https://{hostport}{uri} 302 } # 代码块使用举例: import block__proxy_upstream_args * https://www.baidu.com (block__proxy_upstream_args) { reverse_proxy {args[:]} { header_down -proxy-connection flush_interval 300ms transport http { dial_timeout 10s keepalive 10m keepalive_idle_conns 10240 } } } # 代码块使用举例: import block__proxy_upstream_start_with_host_args www.baidu.com 8.8.8.8 (block__proxy_upstream_start_with_host_args) { reverse_proxy {args[1:]} { header_up Host {args[0]} header_down -proxy-connection flush_interval 300ms transport http { dial_timeout 10s keepalive 10m keepalive_idle_conns 10240 } } } # 举例使用 import block__hide_git (block__handle_hide_git) { denyGit { path (/.*)?/.git(/.*)? } respond denyGit 404 } # 举例使用 import block__compress (block__compress) { encode zstd gzip } # 举例使用 import block__handle_strip_path_and_proxy_args test/* http://baidu.com (block__handle_strip_path_and_proxy_args) { handle /{args[0]} { uri strip_prefix /{args[1]} reverse_proxy {args[2]} { header_down -proxy-connection flush_interval 300ms transport http { dial_timeout 10s keepalive 10m keepalive_idle_conns 10240 } } } } # 举例使用 import block__handle_strip_path_and_file_server_vue3_history_mode_args /test/* /path/to/html/static/file/dir (block__handle_strip_path_and_file_server_vue3_history_mode_args) { handle_path /{args[0]} { file_server { hide .git index index.html } root * {args[1]} try_files {path} /index.html } # endif } # 举例使用 import block__handle_strip_path_and_file_server_only_args /test/* /path/to/html/static/file/dir (block__handle_strip_path_and_file_server_only_args) { handle_path /{args[0]} { file_server { index index.html hide .git } root * {args[1]} } # endif } # 公共 (block__common) { import block__sub_header #import block__logger #import block__cors import block__html_no_cache import block__handle_hide_git import block__compress } # ---------- import ./conf/*.conf

相关推荐

【Dv2Admin】用自己服务器部署d2curd样例站点
【Dv2Admin】用自己服务器部署d2curd样例站点

由于 d2-crud-plus 作者已停止维护,其官方样例站点也无法访问。但对于仍在使用该组件库的项目来说,保留样例站点作为参考模板是非常有必要的。 本文介绍一种基于 宝塔面板 快速部署 d2-crud-plus-example 的方式,用于搭建本地演示站点,供团队内部预览和参考使用。 文章目录… · 2026/9/24 14:01:04

【Dify】多语言自动翻译摘要应用
【Dify】多语言自动翻译摘要应用

多语言内容获取与智能摘要已成为高频需求。如何自动采集网页核心信息、实现高效翻译与摘要,正是实际编程学习与实践的技术挑战。 本文介绍基于Dify工作流的“链文智译Smart”方案,围绕网页采集、多语种翻译和要点提取等流程进行详解,涵盖核心模型设计、节点配置、主要应用场… · 2026/9/24 14:01:04

【Dv3Admin】插件 dvadmin_cloud_storage 数据云存储
【Dv3Admin】插件 dvadmin_cloud_storage 数据云存储

dvadmin_cloud_storage 是基于 Dv3Admin 的云存储插件,支持腾讯云 COS 和阿里云 OSS,实现文件的上传、读取和删除等操作。插件集成于系统设置中,可通过后台界面灵活管理。插件已在 Dv3Admin 框架下完成适配,如需在 Dv2Admin 中使用,可根据实际情况做相应修改。 ⚠️ 注意:… · 2026/9/24 14:01:04

10_自动微分模块与计算图[pytorch框架与神经网络基础]
10_自动微分模块与计算图[pytorch框架与神经网络基础]

8.自动微分模块 训练神经网络时,最常用的算法就是反向传播。在该算法中,参数(模型权重)会根据损失函数关于对应参数的梯度进行调整。为了计算这些梯度,PyTorch内置了名为 torch.autograd 的微分引擎(自动微分模块)。 一般来说,pytorch中模型的… · 2026/9/24 14:29:44

Qwen-Image 2.1是什么?ComfyUI官方AI文生图模型仓库速览:完整文件结构与能力一览
Qwen-Image 2.1是什么?ComfyUI官方AI文生图模型仓库速览:完整文件结构与能力一览

Qwen-Image 2.1是什么?ComfyUI官方AI文生图模型仓库速览:完整文件结构与能力一览 【免费下载链接】Qwen-Image-2.1 项目地址: https://ai.gitcode.com/hf_mirrors/Comfy-Org/Qwen-Image-2.1 Qwen-Image 2.1 是 ComfyUI 官方适配的新一代 AI 文生… · 2026/9/24 14:29:30

自研Pogo Pin测试治具:从选针到Python脚本的完整实战指南
自研Pogo Pin测试治具:从选针到Python脚本的完整实战指南

/* MD / 富文本中的 .toc(含博客园搬家等嵌套结构);.toc-box 在侧栏,不受影响 */#content_views .toc,/* 编辑器常在目录前后插入空 p(:empty 仍占 20px),一并去掉避免顶空隙 */#content_views.markdown_views > p:empty:has(+ .toc),#content_views.markdown_views … · 2026/9/24 14:29:30

Kornia RandomAffine 与 RandomPerspective 的 CUDA 编译修复与随机生成器设备迁移语义
Kornia RandomAffine 与 RandomPerspective 的 CUDA 编译修复与随机生成器设备迁移语义

计算机视觉深度学习人工智能图像处理 【免费下载链接】kornia 🐍 空间人工智能的几何计算机视觉库 项目地址: https://gitcode.com/kornia/kornia 点击查看 免费下载 导读 本篇文章围绕 Kornia 变更记录 changelog.d/4517.fixed.md 展开,聚… · 2026/9/24 14:29:30

8GB 显存跑通图生视频:ComfyUI-WanVideoWrapper 工作流完整指南
8GB 显存跑通图生视频:ComfyUI-WanVideoWrapper 工作流完整指南

8GB 显存跑通图生视频:ComfyUI-WanVideoWrapper 工作流完整指南 【免费下载链接】ComfyUI-WanVideoWrapper 项目地址: https://gitcode.com/GitHub_Trending/co/ComfyUI-WanVideoWrapper 刚把图生视频工作流转进来,画面却卡在第一帧半天不出&… · 2026/9/24 14:29:30

Obsidian第二大脑实战:本地存储、Markdown与双链构建个人知识库
Obsidian第二大脑实战:本地存储、Markdown与双链构建个人知识库

/* MD / 富文本中的 .toc(含博客园搬家等嵌套结构);.toc-box 在侧栏,不受影响 */#content_views .toc,/* 编辑器常在目录前后插入空 p(:empty 仍占 20px),一并去掉避免顶空隙 */#content_views.markdown_views > p:empty:has(+ .toc),#content_views.markdown_views … · 2026/9/24 14:29:30

基于YOLOv8的渔船作业监控系统:从环境搭建到边缘部署全流程
基于YOLOv8的渔船作业监控系统:从环境搭建到边缘部署全流程

简介:这是一套面向计算机、人工智能、自动化等专业学生与教师的毕业设计级项目资源,围绕YOLOv8实现渔船作业监控系统,可用于毕设、课程设计、大作业或项目立项演示。压缩包共97个文件,约24.21MB,以70个Python源码文件为… · 2026/9/24 0:00:13

1D-CNN时间序列建模实战:从Conv1d原理到工业落地
1D-CNN时间序列建模实战:从Conv1d原理到工业落地

简介:面向时间序列数据建模的一维卷积神经网络完整实现,适合深度学习入门者及需要快速验证时序模型的研究者,能够从音频、文本、传感器或股价等序列中挖掘局部特征与时间依赖。压缩包体积很小,只有3KB,内含3个Python脚… · 2026/9/24 0:00:26

柔软的L:汉语语流中被忽视的舌肌张力控制
柔软的L:汉语语流中被忽视的舌肌张力控制

1. 这个“L”不是字母表里的L,而是舌尖上的L最近在几个方言群和语音教学社群里,反复看到有人发一句:“也说字母L:柔软的长舌”。初看以为是英语发音课笔记,点开才发现全是方言爱好者、播音系学生、语言康复师甚至戏曲演… · 2026/9/24 0:00:44

了解更多?预约专属演示

我们的顾问将为您一对一讲解产品与方案

企业微信二维码