使用Caddy代替NGNIX作为反向代理

作为参考,以下是使用 Caddy 作为反向代理的非 Docker 化设置的当前步骤:

1) 调整 Discourse 配置文件

  • 注释掉证书
    templates:
    #  - "templates/web.ssl.template.yml"
    #  - "templates/web.letsencrypt.ssl.template.yml"
    
  • 更改端口映射并禁用 443 映射
    expose:
    - "8080:80"   # http
    # - "443:443" # https
    
  • 强制 HTTPS 来提供静态文件
    env:
    DISCOURSE_FORCE_HTTPS: true
    

2) 重建 Discourse

./launcher rebuild app

3) 设置 Caddy

  • 安装 Caddy,仅使用官方默认设置:Install — Caddy Documentation

  • 调整 /etc/caddy/Caddyfile

    forum.example.com {
          reverse_proxy localhost:8080
    }
    

    如果您有多个站点,您可以仅列出您的域名:

    forum.example.com, forum2.example.com, forum3.example.com {
          reverse_proxy localhost:8080
    }
    

    您还可以运行 systemctl status caddy 来验证默认配置文件位置。

4) 运行 Caddy

systemctl start caddy

更改后重新加载配置:

cd /etc/caddy
caddy reload
2 个赞