最新消息:前端博客、web前端博客、Angularjs、javascript、jQuery、HTML5、CSS3

Caddy应用简单使用教程

杂谈/运维 AZ 1575浏览 0评论

1、快速实现本地目录浏览;需求场景,需要局域分享或web服务

#直接运行
caddy run

#然后通过 https://<local-ip>:2015 访问即可。有些时候内置端口有可能不是2015,这时候需要看控制台回显端口。

指定端口运行

#直接运行
caddy file-server --browse --listen :9527

#然后通过 https://<local-ip>:9527 访问即可。

2、配置域名启动

#加域名启动,使用http/https访问
caddy file-server --domain example.com

#反向代理访问
caddy reverse-proxy --from example.com --to localhost:9000

2、加载配置文件启动

#配置文件启动
caddy run --config ./Caddyfile

#配置文件样版

# redirect www to bare domain
www.example.com {
    redir https://example.com{uri} permanent
}

example.com {
    # log to stdout, which is captured by journalctl
    log {
        output stdout
        format console
    }

    # turn on standard streaming compression
    encode gzip zstd

    # reverse proxy /api to :3000
    reverse_proxy /api/* localhost:3000

    # reverse proxy some "well known" APIs
    reverse_proxy /.well-known/openid-configuration localhost:3000
    reverse_proxy /.well-known/jwks.json localhost:3000

    # serve static files from public folder, but not /api
    @notApi {
        file {
            try_files {path} {path}/ {path}/index.html
        }
        not path /api/*
        not path /.well-known/openid-configuration
        not path /.well-known/jwks.json
    }
    route {
      rewrite @notApi {http.matchers.file.relative}
    }
    root * /srv/example.com/public/
    file_server
}

更多请查看官方文档docs https://webinstall.dev/caddy/

转载请注明:TUTERM.COM » Caddy应用简单使用教程

如果您觉得本文的内容对您的学习有所帮助,您可以支付宝(左)或微信(右):
alipay weichat

您必须 登录 才能发表评论!