
现如今,企业web服务器,可以说nginx,无人不知无人不晓,哪个不怕死的,要来替换nginx呢?——caddy。长江后浪推前浪,作为IT行业人士,请不要大惊小怪,这是必然的,而且速度会很快,所以,我们必须不断学习,走在技术变革的前沿。
caddy是什么?
caddy是一个强大的、企业级、开放源代码的服务器,使用GO语言编写,可以自动实现https加密数据传输。
caddy的特点与优势?
-
默认时自动支持HTTPS
-
ZeroSSL 和 Let's Encrypt实现公共名
-
CA包括完整的内部名和ip信息
-
可以与集群中的其他Caddy配合
-
当服务因为TLS/OCSP/其他证书,出问题时,依然能正常运行
-
能支持万亿级别的请求和管理百万级别TLS证书请求
-
能支持十万级站点的扩展部署
-
默认支持HTTP/1.1, HTTP/2, HTTP/3
-
可以轻松使用Caddyfile进行配置
-
使用json文件实现强大的配置能力
-
可以使用JSON API接口进行动态配置
-
环境运行,没有外部依赖
-
用go语言编写,拥有广告的内存安全
学习caddy
caddy安装
# centos7yum install yum-plugin-copr -yyum copr enable @caddy/caddy -yyum install caddy -y
[root@centos7 ~]# caddyCaddy is an extensible server platform.usage:caddy <command> [<args...>]commands:adapt Adapts a configuration to Caddy's native JSONadd-package Adds Caddy packages (EXPERIMENTAL)build-info Prints information about this buildenviron Prints the environmentfile-server Spins up a production-ready file serverfmt Formats a Caddyfilehash-password Hashes a password and writes base64help Shows help for a Caddy subcommandlist-modules Lists the installed Caddy modulesreload Changes the config of the running Caddy instanceremove-package Removes Caddy packages (EXPERIMENTAL)reverse-proxy A quick and production-ready reverse proxyrun Starts the Caddy process and blocks indefinitelystart Starts the Caddy process in the background and then returnsstop Gracefully stops a started Caddy processtrust Installs a CA certificate into local trust storesuntrust Untrusts a locally-trusted CA certificateupgrade Upgrade Caddy (EXPERIMENTAL)validate Tests whether a configuration file is validversion Prints the versionUse 'caddy help <command>' for more information about a command.Full documentation is available at:https://caddyserver.com/docs/command-line
启动caddy
-
caddy run 启动一个非守护的caddy进程,按ctrl+c停止;
[root@centos7 ~]# caddy run --helpUsage of run:-adapter stringName of config adapter to apply 指定适配的配置文件-config stringConfiguration file 指定config文件-envfile stringEnvironment file to load 指定家族的环境变量-environPrint environment 打印环境变量-pidfile stringPath of file to which to write process ID 存放PID的文件-pingback stringEcho confirmation bytes to this address on success 成功时的回显地址-resumeUse saved config, if any (and prefer over --config file)保存配置,使--config的参数无效-watchWatch config file for changes and reload it automatically发现配置变更时,自动重新加载
caddy run -config /path/caddy.json -watch 这个命令,就是在启动时,加载了一个config文件,使用了watch,那么,在之后过程中,一旦这个配置文件被修改,caddy进程会自动加载,变更信息。-
caddy start启动caddy为守护进程,caddy stop停止。
[root@centos7 ~]# caddy start --helpUsage of start:-adapter stringName of config adapter to apply-config stringConfiguration file-envfile stringEnvironment file to load-pidfile stringPath of file to which to write process ID-watchReload changed config file automatically
run 基本一样。配置文件
{"apps": {"http": {"servers": {"example": {"listen": [":2015"],"routes": [{"handle": [{"handler": "static_response","body": "Hello, Allen!"}]}]}}}}}
curl localhost:2019/load -H "Content-Type: application/json" -d @caddy.json
JSON配置文件模板
{"admin": {"disabled": false,"listen": "", // 绑定的端口,默认2019"enforce_origin": false,"origins": [""],"config": {"persist": false,"load": {•••}},"identity": {"identifiers": [""],"issuers": [{•••}]},"remote": {"listen": "","access_control": [{"public_keys": [""],"permissions": [{"paths": [""],"methods": [""]}]}]}},"logging": {"sink": {"writer": {•••}},"logs": {"": {"writer": {•••},"encoder": {•••},"level": "","sampling": {"interval": 0,"first": 0,"thereafter": 0},"include": [""],"exclude": [""]}}},"storage": {•••},"apps": {•••}}
localhost:80 {respond "xxxxx"}www.domain.com:2016 {respond "xxxxx"}
# 快速启动一个文件服务caddy file-server# 使用一个https服务访问文件服务caddy file-server --domain www.examp.com# 设置代理caddy reverse-proxy --from examp.com --to localhost:9010# 配置Caddyfile文件reverse_proxy 10.0.0.1:9010 10.0.0.2:9010 10.0.0.3:9010 {lb_policy random_choose 2health_path /okhealth_interval 10s}
接口、自动化、互联网大厂真题
简历模板......统统都有
快扫码领取吧~
注:本文柠檬班老师原创,转载需注明来源





文章评论