Caddy VS Nginx,誰領風騷

Caddy 2 is a powerful, enterprise-ready, open source web server with automatic HTTPS written in Go.

— 摘自 Caddy 官網

盤古開發(fā)框架 缺省使用 Caddy 來提供 WebServer 能力和 API 網關角色(反向代理)。(當然,直接換成 Nginx 也是可以的)

Caddy 特性

  • 缺省啟用HTTP/2 協(xié)議,無需任何配置。
  • 缺省全站HTTPS,無需任何配置。(自動申請和續(xù)期證書)
  • 簡單友好的配置文件,支持在線配置 API。
  • golang 開發(fā),幾乎無依賴,部署簡單。
  • 充當 API Gateway, 反向代理后端多個 Web 節(jié)點。
  • 天生插件架構,社區(qū)插件豐富,且自定義插件簡單(寫個插件順便蹭一下 golang 的熱度)。

Nginx 特性

盤古開發(fā)框架 缺省使用 Caddy 而不是 Nginx,并不是說 Nginx 不夠優(yōu)秀。

Caddy 實戰(zhàn)

安裝

Fedora, RHEL/CentOS 8

$ dnf install 'dnf-command(copr)'
$ dnf copr enable @caddy/caddy
$ dnf install caddy

RHEL/CentOS 7

$ yum install yum-plugin-copr
$ yum copr enable @caddy/caddy
$ yum install caddy

Debian, Ubuntu, Raspbian

$ sudo apt install -y debian-keyring debian-archive-keyring apt-transport-https
$ curl -1sLf 'https://dl.cloudsmith.io/public/caddy/stable/gpg.key' | sudo tee /etc/apt/trusted.gpg.d/caddy-stable.asc
$ curl -1sLf 'https://dl.cloudsmith.io/public/caddy/stable/debian.deb.txt' | sudo tee /etc/apt/sources.list.d/caddy-stable.list
$ sudo apt update
$ sudo apt install caddy

常用命令

$ systemctl start[stop|restart] caddy
$ systemctl reload caddy //重新加載配置文件
$ systemctl status caddy //查看運行狀態(tài)

實戰(zhàn)一:Web Server

Web Server 托管靜態(tài)資源,以部署盤古開發(fā)框架項目官網為例。https://pangu.pulanit.com

修改配置文件

# vi /etc/caddy/Caddyfile
pangu.pulanit.com {
        # Set this path to your site's directory.
        root * /var/www/pangu.pulanit.com
        encode gzip
        # Enable the static file server.
        file_server
}

靜態(tài)資源文件上傳到目錄:/var/www/pangu.pulanit.com。

域名解析

域名解析地址必須和上述配置文件中的域名保持一致即可。嘗試訪問:https://pangu.pulanit.com??梢?,網站自動開啟了HTTPS。

實戰(zhàn)二:反向代理

反向代理充當網關角色。詳見官方文檔。

?著作權歸作者所有,轉載或內容合作請聯(lián)系作者
【社區(qū)內容提示】社區(qū)部分內容疑似由AI輔助生成,瀏覽時請結合常識與多方信息審慎甄別。
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發(fā)布,文章內容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務。

相關閱讀更多精彩內容

友情鏈接更多精彩內容