新闻详情

新闻详情

首页 / 资讯中心 / 详情

caddy配置文件Caddyfile示例

发布时间:2026/11/12 0:45:16来源:尧图网络
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
网站建设高端定制企业官网
RELATED

相关资讯

更多精彩内容,欢迎继续阅读

较早相关资讯

最新相关资讯

【外设】之大彩串口显示屏 2026/11/11 13:52:51

【外设】之大彩串口显示屏

大彩串口屏初步使用 1 .官网下载 STM32 屏幕 GUI 设计资料 http://www.gz-dc.com/category/typeid/4112 找到 STM32 Keil 工程,移植相关代码因项目而异进行移植,由于项目简单,本人只对用到的指令接口进行修改。 比如:注意事项&…

阅读更多 →
无法下载Windows系统iso文件 2026/11/10 19:42:40

无法下载Windows系统iso文件

当我遇到这个问题的时候,我打开了一个网站: 登录 然后我打算下载的时候: 突然那个官方的连接就可以下载了:

阅读更多 →
【清华代码熊】DeepSeek V4.1 Flash 后训练详解 2026/11/11 9:31:44

【清华代码熊】DeepSeek V4.1 Flash 后训练详解

📌 上期解析了 DeepSeek V4.1 Flash 模型架构改进,本期解析 DeepSeek V4.1 Flash 预训练/后训练技术: 🌟 预训练:45T 文本 多模态混合语料、直接训练 sparse attention(取消 DeepSeek V4 的 dense 冷启动&…

阅读更多 →
Shuffle-R1: Efficient RL framework for Multimodal Large Language Models via Data-centric Dynamic ... 2026/11/11 5:36:08

Shuffle-R1: Efficient RL framework for Multimodal Large Language Models via Data-centric Dynamic ...

文章主要内容和创新点 主要内容 本文聚焦于多模态大语言模型(MLLM)强化学习(RL)训练中的效率问题,提出了一个名为Shuffle-R1的框架。研究发现,当前RL训练存在两个关键缺陷: 优势值坍缩(Advantage Collapsing):批次中大多数优势值集中在零附近,导致有效梯度信号被淹…

阅读更多 →
PRvL: Quantifying the Capabilities and Risks of Large Language Models for PII Redaction 2026/11/11 15:37:39

PRvL: Quantifying the Capabilities and Risks of Large Language Models for PII Redaction

一、文章主要内容总结 本文聚焦于利用大型语言模型(LLMs)实现个人身份信息(PII)脱敏的研究,旨在解决传统脱敏方法(如基于规则的系统、领域特定命名实体识别(NER)模型)泛化能力差、跨格式/跨语境适应性弱的问题。 研究通过全面评估多种LLM架构(包括密集型LLM(D-LLM…

阅读更多 →
LLaVA-RE: Binary Image-Text Relevancy Evaluation with Multimodal Large Language Model 2026/11/10 17:14:10

LLaVA-RE: Binary Image-Text Relevancy Evaluation with Multimodal Large Language Model

文章主要内容和创新点 主要内容 本文聚焦于二进制图像-文本相关性评估任务(判断图像与文本“相关”或“不相关”),针对该任务中文本格式多样、相关性定义随场景变化等挑战,提出了基于多模态大语言模型(MLLM)的解决方案LLaVA-RE。 模型设计:LLaVA-RE基于LLaVA 1.5架构,…

阅读更多 →

今日资讯

本周资讯

本月资讯

看完文章仍有疑问?

联系尧图顾问,获取一对一建站咨询

立即免费咨询 📞 400-888-8888
📞 ✉