使用Caddy作為Web服務(wù)器
Caddy是一個由Go語言編寫的Web服務(wù)器軟件,可以自動實現(xiàn)HTTPS部署。

為什么使用Caddy
自己的博客想要使用https,懶得去更新證書,Caddy可以快速解決我的問題。
而且相比nginx,Caddy部署起來更簡單,就一個二進制文件;
CaddyFile配置更簡單,很多都是默認(rèn)配置,只要根據(jù)自己的情況,添加需要的參數(shù)即可。
功能豐富,但是很多我暫時用不到,用到再通過插件的方式添加即可。
對于一個博客應(yīng)用來說完全夠用了。
安裝Caddy
在CentOS上可以直接使用yum安裝的,也可以下載對應(yīng)平臺的二進制進行安裝。

安裝命令:
- yum install yum-plugin-copr -y
- yum copr enable @caddy/caddy -y
- yum install caddy -y
配置
配置文件默認(rèn)是在/etc/caddy/Caddyfile,配置文件只要修改好自己的域名,如果需要https直接填寫上http://xxx就可以了,root執(zhí)行自己的網(wǎng)站目錄即可。
我的網(wǎng)站是hugo生成的靜態(tài)站,直接配置目錄。
如果是php可以直接轉(zhuǎn)發(fā)的php_fastcgi。
- # 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 ":80" below with your
- # domain name.
- www.opcai.top https://www.opcai.top http://opcai.top https://opcai.top {
- # Set this path to your site's directory.
- root * /data/webroot
- # Enable the static file server.
- file_server
- # Another common task is to set up a reverse proxy:
- # reverse_proxy /back/* 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
服務(wù)管理
- systemctl enable --now caddy # 啟動并設(shè)置開機啟動
- systemctl reload caddy # 重載配置
總結(jié)
Caddy還有很多強大的功能,慢慢探索。
原文鏈接:https://www.toutiao.com/a7051941957739856391/
版權(quán)聲明:
本站所有文章和圖片均來自用戶分享和網(wǎng)絡(luò)收集,文章和圖片版權(quán)歸原作者及原出處所有,僅供學(xué)習(xí)與參考,請勿用于商業(yè)用途,如果損害了您的權(quán)利,請聯(lián)系網(wǎng)站客服處理。