Caddy可是说是一个最容易上手的服务器端,可以非常方便的把我们的网站或网盘部署在上面,而且Caddy是默认无需额外配置即可提供HTTPS特性的Web服务器。 这期教程主要从Caddy的安装、配置、启动入门,然后参考本站配置文件,逐一解析Caddy的使用方法。

Caddy is said to be the easiest to use server side, it is very convenient to deploy our website or network disk, and Caddy is a web server that provides HTTPS features by default without additional configuration. This tutorial describes mainly from the installation, configuration, startup of Caddy, and then refer to the site configuration file to analyze the use of Caddy.

目录 / LIST

# 安装卸载 | Deployment

  • VPS系统要求:Ubuntu 16+ / Debian 8+ / CentOS 7+
  • System requirement: Ubuntu 16+ / Debian 8+ / CentOS 7+
# 安装 Install
wget -N --no-check-certificate && chmod +x && bash
# 安装插件 Install plugin
bash xxx,xxx
# 卸载 Uninstall
wget -N --no-check-certificate && chmod +x && bash uninstall
  • 这里推广一下逗比的一键安装脚本,直接输入按照提示选择安装完成即可。
  • Just follow this one-click installation script to install caddy server.

# 使用说明 | Instructions

启动Start:/etc/init.d/caddy start
停止Stop:/etc/init.d/caddy stop
重启Restart:/etc/init.d/caddy restart
查看状态Status:/etc/init.d/caddy status
查看启动日志Logfile:tail -f /tmp/caddy.log
安装目录Caddy Dir:/usr/local/caddy
证书位置SSL Dir:/.caddy/acme/域名)/

# 修改配置 | Configuration File

  • Caddy的配置文件名叫Caddyfile,我们直接用Filebrowser在线打开这个/usr/local/caddy/Caddyfile,编辑文件即可。配置文件修改完成后需要重启Caddy生效。
  • Caddy’s configuration file name is Caddyfile. We can open this /usr/local/caddy/Caddyfile directly with Filebrowser and edit the file. After the configuration file is modified, you need to restart Caddy to take effect.

# 启动Caddy | Launch Caddy

  • 在SSH中直接输入/etc/init.d/caddy start即可启动Caddy。
  • Start Caddy by typing /etc/init.d/caddy start directly in SSH.
  • 如果运行出错,可以通过log查看哪里出错了tail -f /tmp/caddy.log
  • If the start goes wrong, you can check the log for error tail -f /tmp/caddy.log.

# 多站配置解析 | Caddyfile example

  • Caddy可以添加多站点配置,以本站的Caddyfile为例:
  • Caddy can add a multi-site configuration, taking the Caddyfile of this site as an example: {
 root /home/marsgrid/public
 errors {
  * /home/marsgrid/public/404.html
} {
} {
 proxy /
} {
 proxy /
 basicauth / admin admin

## 博客配置 | Blog Config

指令Directives 说明Description
gzip 启用压缩 Enables gzip compression
root 指向网站根目录 Specifies the root of the site
tls 配置HTTPS连接,需要填写邮箱,Caddy会自动申请证书 Configures HTTPS connections, mail addr. needed
errors 指向404或500错误页面 Set custom error pages

你可能会感兴趣 | Maybe interested in


## 设置跳转 | Redirection

指令Directives 说明Description
redir 将www域名重定向 Redirect www domain

## 反代站点 | Proxy sites

指令Directives 说明Description
proxy 实现反向代理 Reverse proxy enabled
  • 通过设置本地反向代理,可以把之前部署的Filebrowser挂到我们的域名下,proxy /,注意标明端口号。
  • By setting the local reverse proxy, you can hang the previously deployed Filebrowser under our domain name, proxy /, and note the port.

你可能会感兴趣 | Maybe interested in


  • 还可以设置其他地址的反向代理,比如反代一下谷歌?打造自己的镜像站。
  • Can also set up a reverse proxy for other sites, such as the Google? You can now build your own mirror sites.
指令Directives 说明Description
basicauth 设置用户名和口令 Set username and password
  • 与此同时,可以把镜像站设置密码,可以登录本站导航栏中的搜索|Search镜像站试一下。
  • At the same time, you can set the password to login your mirror sites. Simply go to 搜索|Search on the top to login.

# 参考指南 | User Guide

  • 如果你想了解更多Caddy的使用方法,可以访问下方的官方指南。
  • If you want to learn more about how to use Caddy, you can visit the official guide below.

Caddy 中文文档:

Caddy User Guide:

• 本文作者 | Author info >> MAXH
• 来源链接 | Source link >> Caddy从入门到多站配置教程 | Ready your sites with Caddy
• 发表评论 | Make comments >>