caddy server && caddyfile
This page describes how to configure Caddy using the Caddyfile.
Introduction
The term "Caddyfile" describes a text file that changes how Caddy works. It's similar in purpose to httpd.conf or nginx.conf. The Caddyfile file can be named anything, but by default, Caddy will look for a file called Caddyfile in the current directory. You can specify another location for the Caddyfile using the -conf
flag:
$ caddy -conf="/path/to/Caddyfile"
If your Caddyfile is within the root of your site, don't worry. Caddy will respond with "404 Not Found" to keep it hidden for you.
Syntax
The Caddyfile always starts with the address of the site to serve:
localhost:2020
After that, each line is expected to start with a valid directive. Directives are keywords that are recognized by Caddy, like gzip
:
localhost:2020
gzip
Directives usually have one or more arguments after them:
localhost:2020
gzip
log ../access.log
Some directives may need more configuration than can fit easily on one line. As such, the syntax of a directive may permit you to open a block and set more parameters. The open curly brace must be at the end of a line:
localhost:2020
gzip
log ../access.logmarkdown /blog { css /blog.css js /scripts.js }
If the directive block is left empty, you should omit the curly braces entirely.
Arguments that contain whitespace must be enclosed in quotes "
.
The Caddyfile can also have comments starting with the #
character:
# Comments can start a linefoobar # or go at the end
To configure multiple servers (virtual hosts) with a single Caddyfile, you must use curly braces around each site block:
mysite.com { root /www/mysite.com }
sub.mysite.com {
root /www/sub.mysite.comgziplog ../access.log
}
As with directives, the open curly brace must be at the end of the same line. The closing curly brace must be on its own line.
For sites which share the same configuration, specify multiple addresses:
localhost:2020, https://site.com, http://mysite.com {
...
}
Site addresses can also be defined under a specific path, or have wildcards in place of domain labels from the left side:
example.com/static*.example.com
Note that using a path in your site address routes requests by longest matching prefix. If your base path is a directory, you may wish to suffix the path with a forward slash /
.
Use of environment variables is allowed in addresses and arguments. They must be enclosed in curly braces, and you can use either Unix or Windows variable formats:
localhost:{$PORT}root {%SITE_ROOT%}
Either syntax works on any platform. A single environment variable does not expand out into multiple arguments/values.
Addresses
Addresses are specified in the form scheme://host:port/path
, where all but one are optional. The host portion is usually localhost or the domain name. The default port is 2015 (unless the site qualifies for automatic HTTPS, in which case it's 443). The scheme portion is another way to specify a port. Valid schemes are "http" or "https" which represent, respectively, ports 80 and 443. If both a scheme and port are specified, the port will override the scheme. For example:
:2015 # Host: (any), Port: 2015localhost # Host: localhost, Port: 2015localhost:8080 # Host: localhost, Port: 8080example.com # Host: example.com, Port: 443http://example.com # Host: example.com, Port: 80https://example.com # Host: example.com, Port: 443http://example.com:1234 # Host: example.com, Port: 1234https://example.com:80 # Error! HTTPS on port 80*.example.com # Hosts: *.example.com, Port: 443example.com/foo/ # Host: example.com, Port: 443, Path: /foo//foo/ # Host: (any), Port: 2015, Path: /foo/
Directives
Each line in a server block must start with a valid directive. The order they appear in does not matter. A directive is the first word of a line, and it may be followed by arguments, which are extra values used to configure the directive. A directive may also open a block to specify more parameters.
Most directives invoke a layer of middleware. Middleware is a small layer in the application that handles HTTP requests and does one thing really well. Middleware are chained together (pre-compiled, if you will) at startup. Only middleware handlers which are invoked from the Caddyfile will be chained in, so small Caddyfiles are very fast and efficient.
The syntax of arguments varies from directive to directive. Some have required arguments, others don't. Consult the documentation of each directive for their signatures.
Path Matching
Some directives accept an argument that specifies a base path to match. A base path is a prefix, so if the URL starts with the base path, it will be a match. For example, a base path of /foo
will match requests to /foo
, /foo.html
, /foobar
, and /foo/bar.html
. If you want to limit a base path to match a specific directory only, then suffix it with a forward slash like /foo/
, which will not match /foobar
.
caddy server && caddyfile的更多相关文章
- caddy server 默认https && http2的验证
1. 下载 https://caddyserver.com/ 注意选择应该包含的模块,此次包含了git 插件 2. 配置 使用 Caddyfile 内容如下: ro ...
- caddy server 了解
Caddy 是一个Go写的服务器软件,官方的宣传语“The HTTP/2 web server with automatic HTTPS”以及“Serve The Web Like It's 2016 ...
- caddy server 几个常用插件
1.log日志 log /var/www/log/example.log 2.目录访问 browse 3.gzip压缩 gzip 4.自主ssl证书 tls /path/ssl/exa ...
- Caddy – 方便够用的 HTTPS server 新手教程
最近发现了一个 golang 开发的 HTTP server,叫做 Caddy,它配置起来十分简便,甚至可以 28 秒配置好一个支持 http2 的 server ,而且对各种 http 新特性都支持 ...
- Caddy源码阅读(二)启动流程与 Event 事件通知
Caddy源码阅读(二)启动流程与 Event 事件通知 Preface Caddy 是 Go 语言构建的轻量配置化服务器.https://github.com/caddyserver/caddy C ...
- caddy配置php-fpm
特码的,谷歌又用不了了. 吐槽完毕,正文如下: caddy是一个用go语言开发的服务器,可用作web端. caddy本身支持 -conf caddyfile的配置 在命令行中的体现: caddy -c ...
- 让子弹飞,零成本让你的网站更快一点,boxopened http/3 (QUIC) 协议实战
最近HTTP-over-QUIC 协议被正式命名为 HTTP/3,协议带来的最大改变是协议底层将采用UDP协议,而不再是TCP协议,这样的好处吗,就是更低时延,更好的拥塞控制,更精确的RTT时间,更高 ...
- Docker 使用 Dockerfile 构建自己的镜像
可以使用Dockerfile的配置文件方式进行构建自己的镜像 下面利用docker构建一个Caddy web服务器 构建脚本 Dockerfile有自己的命令,下面使用了一些比较常用的命令,更多的Do ...
- 解决了好几个软件的构建问题,在解决部署问题,bluemix部署
https://www.puteulanus.com/archives/838#comment-961新版 Bluemix 一键搭建 SS 脚本 https://blog.feixueacg.com/ ...
随机推荐
- pahlcon:循环调度(Dispatch Loop)或跳转
循环调度将会在分发器执行,直到没有action需要执行为止.在上面的例子中,只有一个action 被执行到.现在让我们来看下“forward”(转发)怎样才能在循环调度里提供一个更加复杂的操作流,从而 ...
- TileMode(平铺模式) 枚举的成员:
TileMode(平铺模式) 枚举的成员: 成员名称 说明 FlipX 与 Tile 相同,只不过图块的交替列被水平翻转. 基本图块本身不翻转. FlipXY FlipX 和 FlipY ...
- 1012: [JSOI2008]最大数maxnumber 线段树
https://www.lydsy.com/JudgeOnline/problem.php?id=1012 现在请求你维护一个数列,要求提供以下两种操作:1. 查询操作.语法:Q L 功能:查询当前数 ...
- 在Linux下安装JDK环境
解压java安装包到指定目录下,这里为/data/software/java/, 然后在/etc/profile添加以下内容: JAVA_HOME =/data/software/java/jdk1. ...
- Linux服务器上安装tomcat
安装软件 : apache-tomcat-9.0.0.M1.tar.gz(下载地址http://tomcat.apache.org/) 步骤一 Tomcat是其中一个开源的且免费的java Web服务 ...
- 【css】25个漂亮的响应式布局的web设计【转】
响应的web设计的做法是提高用户的浏览质量,并在不同设备上能够完美的浏览使用,就像大前端推出的D7主题.看看下面美丽的响应的网站布局,通过本文你会在以后的设计中找到响应的web设计的灵感. 1.Mar ...
- codis3.2安装配置中的一些问题
1.参考文档与参考资料问题 安装codis集群之前,我先在网上找资料,然后又到github的项目官方地址找,不得不说,相关的资料不好找,而且找到之后有些东西说的也不是很清楚.由于codis版本迭代的问 ...
- VS2005 使用体验
鄙人记性真心不好,看了就忘.此文记录下日常小工具的tips. 1)VS的小番茄: 破解版 Visual.Assist.X.V10.6.1833支持VS2010 VS2008 VS2005 VC6 破解 ...
- Python模块化
在Python中,一个.py文件就称之为一个模块(Module). 模块化的好处: 1.大大提高了代码的可维护性. 2.编写代码不必从零开始.当一个模块编写完毕,就可以被其他地方引用.我们在编写程序的 ...
- [置顶]
不再迷惑,也许之前你从未真正懂得 Scroller 及滑动机制
学习本来就是从困惑中摸索问题答案的过程,能够描述出来问题就已经成功了一半.只要发现了困扰你的东西是什么,那么你就离解答出来不远了.----肯尼斯 R. 莱伯德 一直以来,Android 开发中绕不过去 ...