这是我的Caddyfile:

localhost:8090
# log log/access.log

# tls sec/cert.pem sec/key.pem

以下是我正在try 运行的一款Golang应用程序:

% caddy run
2023/06/06 03:55:25.997 INFO    using adjacent Caddyfile
2023/06/06 03:55:25.999 INFO    admin   admin endpoint started  {"address": "localhost:2019", "enforce_origin": false, "origins": ["//localhost:2019", "//[::1]:2019", "//127.0.0.1:2019"]}
2023/06/06 03:55:26.000 INFO    tls.cache.maintenance   started background certificate maintenance      {"cache": "0xc000215c00"}
2023/06/06 03:55:26.000 INFO    http    enabling automatic HTTP->HTTPS redirects        {"server_name": "srv0"}
2023/06/06 03:55:26.001 INFO    tls     cleaning storage unit   {"description": "FileStorage:/home/me123/.local/share/caddy"}
2023/06/06 03:55:26.001 INFO    tls     finished cleaning storage units
2023/06/06 03:55:26.044 INFO    pki.ca.local    root certificate is already trusted by system   {"path": "storage:pki/authorities/local/root.crt"}
2023/06/06 03:55:26.044 INFO    http    enabling HTTP/3 listener        {"addr": ":8090"}
2023/06/06 03:55:26.044 INFO    http.log        server running  {"name": "srv0", "protocols": ["h1", "h2", "h3"]}
2023/06/06 03:55:26.044 INFO    tls.cache.maintenance   stopped background certificate maintenance      {"cache": "0xc000215c00"}
Error: loading initial config: loading new config: http app module: start: listening on :80: listen tcp :80: bind: permission denied

这与端口80有什么关系?我想在8090上运行它,为什么它不工作?

推荐答案

http    enabling automatic HTTP->HTTPS redirects

启用HTTP-&>HTTPS重定向时,Caddy将侦听端口80.看看这个reported issue.根据该期的 comments ,您可以通过以下方式解决该问题

  • 无论是 Select --disable-redirects的球童
  • 或者通过在Caddyfile中使用全局选项http_port来更改Caddy用于HTTP的端口.

事实上,它在the official doc中被提到(没有解释):

如果HTTP和HTTPS端口(分别为80和443)是操作系统上的特权端口,则需要以提升的特权运行或使用更高的端口.要使用更高的端口,只需将地址更改为类似localhost:2015 and使用http_port Caddyfile选项更改HTTP端口.

Go相关问答推荐

语法-for循环中的initit陈述是否允许分配?

Makefile:现有文件上没有这样的文件或目录,不加载环境变量

仅呈现一个模板的GIN Web应用程序

如何使用Gorilla WebSockets实现Http.Hijacker&;alexedwards/scs/v2

JetBrains Goland,禁用突出显示测试文件

无法使用Segentio;S Kafka-Go连接到融合的Kafka

包裹网.Conn导致挂起读取

如何使redis池的等待超时

我怎样才能改进这个嵌套逻辑以使其正常工作并提高性能

Go 中如何判断 struct 体是否包含另一个 struct 体?

Go test "-run -" 标志执行测试更快

Exchange Web 服务 - 使用 soap xml 请求查找所有未读邮件

当图像是对象数组的元素时,如何显示存储为页面资源的图像?

如何在 Go 中编写示例测试?

也许在 golang 中包(字符串和字符串类型不匹配)

在删除级联时无法在 Gorm 中按预期工作

无法访问 Go 模块导入的远程存储库

Go 使用 struct 作为接口而不实现所有方法

在 VSCode 中使用命令行参数调试 Go 测试

不能使用 *T 类型的变量作为参数类型