Caddy安裝 - CentOS、MacOS

官網(wǎng):https://caddyserver.com

GitHub:https://github.com/caddyserver/caddy/releases

linux - CentOS - 7.9

下載二進(jìn)制文件

wget https://github.com/caddyserver/caddy/releases/download/v2.2.1/caddy_2.2.1_linux_amd64.tar.gz

解壓

tar -zxf caddy_2.2.1_linux_amd64.tar.gz caddy

復(fù)制至/usr/local/bin

mv ./caddy /usr/local/bin/

查看caddy版本够掠,測(cè)試是否安裝成功

caddy version

創(chuàng)建用戶組

groupadd --system caddy

添加用戶

useradd --system \
--gid caddy \
--create-home \
--home-dir /var/lib/caddy \
--shell /usr/sbin/nologin \
--comment "Caddy web server" \
caddy

添加 /etc/systemd/system/caddy.service
文件地址:caddy.service:https://github.com/caddyserver/dist/blob/master/init/caddy.service
內(nèi)容如下觉鼻,可直接復(fù)制

# caddy.service
#
# For using Caddy with a config file.
#
# Make sure the ExecStart and ExecReload commands are correct
# for your installation.
#
# See https://caddyserver.com/docs/install for instructions.
#
# WARNING: This service does not use the --resume flag, so if you
# use the API to make changes, they will be overwritten by the
# Caddyfile next time the service is restarted. If you intend to
# use Caddy's API to configure it, add the --resume flag to the
# `caddy run` command or use the caddy-api.service file instead.

[Unit]
Description=Caddy
Documentation=https://caddyserver.com/docs/
After=network.target network-online.target
Requires=network-online.target

[Service]
User=caddy
Group=caddy
ExecStart=/usr/bin/caddy run --environ --config /etc/caddy/Caddyfile
ExecReload=/usr/bin/caddy reload --config /etc/caddy/Caddyfile
TimeoutStopSec=5s
LimitNOFILE=1048576
LimitNPROC=512
PrivateTmp=true
ProtectSystem=full
AmbientCapabilities=CAP_NET_BIND_SERVICE

[Install]
WantedBy=multi-user.target

調(diào)整權(quán)限

chmod 755 caddy.service

在/etc目錄下創(chuàng)建文件夾

mkdir caddy

在/etc/caddy/ 添加Caddyfile
默認(rèn)配置:https://github.com/caddyserver/dist/blob/master/config/Caddyfile
內(nèi)容如下,可直接復(fù)制

# The Caddyfile is an easy way to configure your Caddy web server.
#
# Unless the file starts with a global options block, the first
# uncommented line is always the address of your site.
#
# To use your own domain name (with automatic HTTPS), first make
# sure your domain's A/AAAA DNS records are properly pointed to
# this machine's public IP, then replace the line below with your
# domain name.
:80

# Set this path to your site's directory.
root * /usr/share/caddy

# Enable the static file server.
file_server

# Another common task is to set up a reverse proxy:
# reverse_proxy localhost:8080

# Or serve a PHP site through php-fpm:
# php_fastcgi localhost:9000

# Refer to the Caddy docs for more information:
# https://caddyserver.com/docs/caddyfile

添加系統(tǒng)命令伐割,設(shè)置開機(jī)啟動(dòng)

ln -s /usr/local/bin/caddy /usr/bin/caddy
systemctl daemon-reload
systemctl enable caddy

啟動(dòng)caddy

systemctl start caddy

查看caddy啟動(dòng)狀態(tài)

systemctl status caddy

測(cè)試一下诫咱,查看配置信息

curl localhost:2019/config/

MacOS

安裝

brew install caddy

進(jìn)入安裝目錄 /usr/local/Cellar/caddy/2.2.1
安裝的是2.2.1笙隙,可通過(guò)caddy version查看。

cd /usr/local/Cellar/caddy/2.2.1
cat homebrew.mxcl.caddy.plist

內(nèi)容如下

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
  <dict>
    <key>KeepAlive</key>
    <true/>
    <key>Label</key>
    <string>homebrew.mxcl.caddy</string>
    <key>ProgramArguments</key>
    <array>
      <string>/usr/local/opt/caddy/bin/caddy</string>
      <string>run</string>
      <string>--config</string>
      <string>/usr/local/etc/Caddyfile</string>
    </array>
    <key>RunAtLoad</key>
    <true/>
    <key>StandardOutPath</key>
    <string>/usr/local/var/log/caddy.log</string>
    <key>StandardErrorPath</key>
    <string>/usr/local/var/log/caddy.log</string>
  </dict>
</plist>

這個(gè)是Caddyfile配置文件路徑

<string>/usr/local/etc/Caddyfile</string>

進(jìn)入 /usr/local/etc

cd /usr/local/etc

這個(gè)時(shí)候會(huì)發(fā)現(xiàn)沒(méi)有這個(gè)文件坎缭,安裝時(shí)沒(méi)有生成該文件
下面在/usr/local/etc/目錄創(chuàng)建caddy文件夾

mkdir caddy
cd caddy

caddy文件夾添加Caddyfile
默認(rèn)配置文件:https://github.com/caddyserver/dist/blob/master/config/Caddyfile

vi Caddyfile

Caddyfile內(nèi)容如下竟痰,可直接復(fù)制

# The Caddyfile is an easy way to configure your Caddy web server.
#
# Unless the file starts with a global options block, the first
# uncommented line is always the address of your site.
#
# To use your own domain name (with automatic HTTPS), first make
# sure your domain's A/AAAA DNS records are properly pointed to
# this machine's public IP, then replace the line below with your
# domain name.
:80

# Set this path to your site's directory.
root * /usr/share/caddy

# Enable the static file server.
file_server

# Another common task is to set up a reverse proxy:
# reverse_proxy localhost:8080

# Or serve a PHP site through php-fpm:
# php_fastcgi localhost:9000

# Refer to the Caddy docs for more information:
# https://caddyserver.com/docs/caddyfile

接下來(lái)修改 homebrew.mxcl.caddy.plist 文件

cd /usr/local/Cellar/caddy/2.2.1
vi homebrew.mxcl.caddy.plist
<string>/usr/local/etc/Caddyfile</string>
修改為
<string>/usr/local/etc/caddy/Caddyfile</string>

啟動(dòng)caddy

brew services start caddy

訪問(wèn):127.0.0.1:2019/config

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
  • 序言:七十年代末,一起剝皮案震驚了整個(gè)濱河市掏呼,隨后出現(xiàn)的幾起案子坏快,更是在濱河造成了極大的恐慌,老刑警劉巖憎夷,帶你破解...
    沈念sama閱讀 218,546評(píng)論 6 507
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件莽鸿,死亡現(xiàn)場(chǎng)離奇詭異,居然都是意外死亡岭接,警方通過(guò)查閱死者的電腦和手機(jī)富拗,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 93,224評(píng)論 3 395
  • 文/潘曉璐 我一進(jìn)店門臼予,熙熙樓的掌柜王于貴愁眉苦臉地迎上來(lái)鸣戴,“玉大人,你說(shuō)我怎么就攤上這事粘拾≌” “怎么了?”我有些...
    開封第一講書人閱讀 164,911評(píng)論 0 354
  • 文/不壞的土叔 我叫張陵缰雇,是天一觀的道長(zhǎng)入偷。 經(jīng)常有香客問(wèn)我,道長(zhǎng)械哟,這世上最難降的妖魔是什么疏之? 我笑而不...
    開封第一講書人閱讀 58,737評(píng)論 1 294
  • 正文 為了忘掉前任,我火速辦了婚禮暇咆,結(jié)果婚禮上锋爪,老公的妹妹穿的比我還像新娘丙曙。我一直安慰自己,他們只是感情好其骄,可當(dāng)我...
    茶點(diǎn)故事閱讀 67,753評(píng)論 6 392
  • 文/花漫 我一把揭開白布亏镰。 她就那樣靜靜地躺著,像睡著了一般拯爽。 火紅的嫁衣襯著肌膚如雪索抓。 梳的紋絲不亂的頭發(fā)上,一...
    開封第一講書人閱讀 51,598評(píng)論 1 305
  • 那天毯炮,我揣著相機(jī)與錄音逼肯,去河邊找鬼。 笑死桃煎,一個(gè)胖子當(dāng)著我的面吹牛汉矿,可吹牛的內(nèi)容都是我干的。 我是一名探鬼主播备禀,決...
    沈念sama閱讀 40,338評(píng)論 3 418
  • 文/蒼蘭香墨 我猛地睜開眼洲拇,長(zhǎng)吁一口氣:“原來(lái)是場(chǎng)噩夢(mèng)啊……” “哼!你這毒婦竟也來(lái)了曲尸?” 一聲冷哼從身側(cè)響起赋续,我...
    開封第一講書人閱讀 39,249評(píng)論 0 276
  • 序言:老撾萬(wàn)榮一對(duì)情侶失蹤,失蹤者是張志新(化名)和其女友劉穎另患,沒(méi)想到半個(gè)月后纽乱,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體,經(jīng)...
    沈念sama閱讀 45,696評(píng)論 1 314
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡昆箕,尸身上長(zhǎng)有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 37,888評(píng)論 3 336
  • 正文 我和宋清朗相戀三年解寝,在試婚紗的時(shí)候發(fā)現(xiàn)自己被綠了。 大學(xué)時(shí)的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片搓谆。...
    茶點(diǎn)故事閱讀 40,013評(píng)論 1 348
  • 序言:一個(gè)原本活蹦亂跳的男人離奇死亡嘹害,死狀恐怖,靈堂內(nèi)的尸體忽然破棺而出纤泵,到底是詐尸還是另有隱情骆姐,我是刑警寧澤,帶...
    沈念sama閱讀 35,731評(píng)論 5 346
  • 正文 年R本政府宣布捏题,位于F島的核電站玻褪,受9級(jí)特大地震影響,放射性物質(zhì)發(fā)生泄漏公荧。R本人自食惡果不足惜带射,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 41,348評(píng)論 3 330
  • 文/蒙蒙 一、第九天 我趴在偏房一處隱蔽的房頂上張望循狰。 院中可真熱鬧窟社,春花似錦捻浦、人聲如沸。這莊子的主人今日做“春日...
    開封第一講書人閱讀 31,929評(píng)論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽(yáng)。三九已至钠四,卻和暖如春盗扒,著一層夾襖步出監(jiān)牢的瞬間,已是汗流浹背缀去。 一陣腳步聲響...
    開封第一講書人閱讀 33,048評(píng)論 1 270
  • 我被黑心中介騙來(lái)泰國(guó)打工侣灶, 沒(méi)想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留,地道東北人缕碎。 一個(gè)月前我還...
    沈念sama閱讀 48,203評(píng)論 3 370
  • 正文 我出身青樓褥影,卻偏偏與公主長(zhǎng)得像,于是被迫代替她去往敵國(guó)和親咏雌。 傳聞我的和親對(duì)象是個(gè)殘疾皇子凡怎,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 44,960評(píng)論 2 355

推薦閱讀更多精彩內(nèi)容