Caddy是一个Go写的服务器软件,官方的宣传语“The HTTP/2 web server with automatic HTTPS”以及“Serve The Web Like It's 2016”简明表达了这个软件的优点和趋势,它拥有基本的apache或者nginx有的web server模块,同时还有一些很有特色的功能,比如:
HTTP/2
Automatic HTTPS
Multi-core
Websockets
Markdown
IPv6
Git
…...
用Caddy我们就可以很方便的部署一个Markdown文本作为静态网站访问,或者它的Git指令完成代码的自动化部署,当然它很大的特色就是它的语法非常简洁,比nginx还要简单,配置部署起来很方便,下面随便举几个例子吧。
对网站添加BasicAuth,用户名ryan,密码 12345
basicauth / ryan 12345
用CORS解决跨域问题
cors / {
origin http://allowedSite.com
origin http://anotherSite.org https://anotherSite.org
methods POST,PUT
allow_credentials false
max_age 3600
allowed_headers X-Custom-Header,X-Foobar
exposed_headers X-Something-Special,SomethingElse
}
IP过滤
ipfilter / {
rule block
ip 212.10.15.0-255 213.10.15.0-10 5.23.4.24
blockpage /local/data/default.html
}
HTTPS 配置
tls ../cert.pem ../key.pem
实在太简单了配置起来,具体还有其他简洁到哭的指令可以看官方的User Guide,很快就刷完了。
既然Caddy自动部署https,而且是通过Let's Encrypt,那么就实践一下,本博客是用Ghost 搭建,Nginx代理的,现在就改用Caddy,并支持https,步骤大体如下:
证书申请请移步 Let's Encrypt
Caddy 安装很简单,直接下载 https://caddyserver.com/docs/getting-started
配置Caddyfile,看起来指令简洁明了
https://www.yuansir-web.com, http://www.yuansir-web.com, http://yuansir-web.com { redir https://yuansir-web.com{uri} tls yuansir88@gmail.com } https://yuansir-web.com { gzip errors { log /var/log/caddy/yuansir-web.error.log { size 50 age 30 keep 5 } } log /var/log/caddy/yuansir-web.access.log tls yuansir88@gmail.com proxy / http://127.0.0.1:2368 { proxy_header X-Real-IP {remote} proxy_header HOST {host} proxy_header X-Forwarded-Proto {scheme} } }
用supservisor来管理Caddy运行
[program:caddy] command=/usr/bin/caddy -conf="/var/www/Caddyfile" directory=/var/www ; directory to cwd to before exec (def no cwd) autostart=true ; start at supervisord start (default: true) autorestart=unexpected ; whether/when to restart (default: unexpected) startsecs=1 ; number of secs prog must stay running (def. 1) startretries=3 ; max # of serial start failures (default 3) exitcodes=0,2 ; 'expected' exit codes for process (default 0,2) stopsignal=QUIT ; signal used to kill process (default TERM) stopwaitsecs=10 ; max num secs to wait b4 SIGKILL (default 10) stopasgroup=false ; send stop signal to the UNIX process group (default false) user=www ; setuid to this UNIX account to run the program redirect_stderr=true ; redirect proc stderr to stdout (default false) stdout_logfile=/var/log/caddy.log ; stdout log path, NONE for none; default AUTO stderr_logfile=/var/log/caddyerr.log ; stderr log path, NONE for none; default AUTO
将网站的静态资源CDN换成支持https的CDN
好了,就这么简单,Nginx切换成Caddy,并支持https了,真是多快好省。
Caddy,Server
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
更新日志
- 华少翌.2005-华少翌【中唱艺能】【WAV+CUE】
- 群星《十二女声Ⅱ》[WAV/CUE/分轨][527MB]
- 大自然音乐系列《漫步在山裡》[WAV/CUE/分轨][502.8MB]
- 大自然音乐系列《星光夜语》[WAV/CUE/分轨][453.3MB]
- 史依弘《史依弘交响乐京剧演唱专辑HQ》头版限量编号[WAV+CUE]
- 曼丽2020《女人三十风继续吹》HQCD[WAV+CUE]
- 曼丽2021《女人三十2雾之恋》HQCD[WAV+CUE]
- 隔壁老樊.2019-我曾【好听音乐】【FLAC分轨】
- 高林生.1993-牵挂你的人是我【白天鹅】【WAV+CUE】
- 洪卓立.2012-找个懂我的女孩(国专)【英皇娱乐】【WAV+CUE】
- 曼丽2022《女人三十3晚秋》HQCD[WAV+CUE]
- 曼丽2018《女人三十4冬天》HQCD[WAV+CUE]
- 柏菲-《好歌30年壹》限量开盘母带ORMCD[低速原抓WAV+CUE]
- 大自然音乐系列《水舞》[WAV/CUE/分轨][424.3MB]
- 大自然音乐系列《星光夜语》[WAV/CUE/分轨][453.3MB]