Caddy服务器尝试打开端口80而不是8090。

huangapple go评论98阅读模式
英文:

Caddy server tries to open port 80 instead if 8090

问题

以下是翻译好的内容:

这是我的Caddyfile配置文件:

localhost:8090
# log log/access.log

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

这是我尝试运行一个Golang应用程序的命令:

% caddy run
2023/06/06 03:55:25.997 INFO    使用相邻的Caddyfile
2023/06/06 03:55:25.999 INFO    admin   管理端点已启动  {"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   启动后台证书维护  {"cache": "0xc000215c00"}
2023/06/06 03:55:26.000 INFO    http    启用自动HTTP->HTTPS重定向  {"server_name": "srv0"}
2023/06/06 03:55:26.001 INFO    tls     清理存储单元  {"description": "FileStorage:/home/me123/.local/share/caddy"}
2023/06/06 03:55:26.001 INFO    tls     完成清理存储单元
2023/06/06 03:55:26.044 INFO    pki.ca.local    根证书已被系统信任  {"path": "storage:pki/authorities/local/root.crt"}
2023/06/06 03:55:26.044 INFO    http    启用HTTP/3监听器  {"addr": ":8090"}
2023/06/06 03:55:26.044 INFO    http.log        服务器正在运行  {"name": "srv0", "protocols": ["h1", "h2", "h3"]}
2023/06/06 03:55:26.044 INFO    tls.cache.maintenance   停止后台证书维护  {"cache": "0xc000215c00"}
错误:加载初始配置:加载新配置:http应用模块:启动:监听 :80:绑定权限被拒绝

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

英文:

Here's my Caddyfile:

localhost:8090
# log log/access.log

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

Here's I'm trying to run a Golang app:

% 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

What does it have to do with port 80? I want to run it on 8090, why doesn't it work?

答案1

得分: 0

Caddy在启用HTTP->HTTPS重定向时将监听端口80。请参考此报告的问题。根据该问题中的评论,你可以通过以下方式解决该问题:

  • 使用--disable-redirects选项运行Caddy
  • 或者在Caddyfile中使用http_port全局选项来更改Caddy用于HTTP的端口。

实际上,在官方文档中提到了这一点(没有解释):

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

英文:
http    enabling automatic HTTP->HTTPS redirects

Caddy will listen on port 80 when HTTP->HTTPS redirect is enabled. See this reported issue. According to the comments in that issue, you can address the issue by

  • either running Caddy with the --disable-redirects option
  • or changing the port that Caddy uses for HTTP by using the http_port global option in a Caddyfile.

In fact, it's mentioned in the official doc (without an explanation):

> If the HTTP and HTTPS ports (80 and 443, respectively) are privileged ports on your OS, you will either need to run with elevated privileges or use a higher port. To use a higher port, just change the address to something like localhost:2015 and change the HTTP port using the http_port Caddyfile option.

huangapple
  • 本文由 发表于 2023年6月6日 11:58:03
  • 转载请务必保留本文链接:https://go.coder-hub.com/76411366.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定