# Caddy的下载、安装、配置、启动

## 一、下载

进入官网下载地址：<https://caddyserver.com/v1/download>\
可获得下载caddy\_v1.0.3\_linux\_amd64.tar.gz的链接和无需下载直接安装脚本：\
下载链接：<https://caddyserver.com/download/linux/amd64?license=personal&telemetry=off>\
安装脚本：curl <https://getcaddy.com> | bash -s personal

<div align="left"><img src="/files/-LthGUjBIxgY1nOPV0aJ" alt=""></div>

<div align="left"><img src="/files/-LthGwHbNdwutom6R-UP" alt=""></div>

## 二、安装

方法一：执行上面的安装脚本\
\
方法二：上传下载好的caddy\_v1.0.3\_linux\_amd64.tar.gz压缩包，提取压缩包里的caddy文件到自定目录例如/usr/local/bin\
解压到指定目录：tar -zxvf caddy\_v1.0.3\_linux\_amd64.tar.gz -C /usr/local/bin\
或者仅提取caddy一个文件：tar -zxvf caddy\_v1.0.3\_linux\_amd64.tar.gz -C /usr/local/bin caddy

## 三、配置Caddyfile文件

创建Caddyfile文件，文件内容举例如下：\
mysite.com {\
&#x20;root /www/mysite.com\
}\
\
sub.mysite.com {\
&#x20;root /www/sub.mysite.com\
&#x20;gzip\
&#x20;log ../access.log\
}\
\
保存，Caddyfile文件如果没有保存到网站目录和caddy文件目录，运行caddy时一般还需写出Caddyfile详细路径，例如：caddy -conf ../path/to/Caddyfile

## 四、启动运行

到网站所在目录，执行caddy即可\
但为了能在后台运行，一般会到网站目录下执行这句命令：\
nohup /usr/local/bin/caddy > /tmp/caddy.log 2>&1 &\
\
关闭后台caddy的命令：pkill caddy\
如果是在前台运行，按Ctrl+C即可


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://cgo.gitbook.io/my-it-blog/linux-1/caddy-de-xia-zai-an-zhuang-pei-zhi-qi-dong.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
