[beego]http,https可以同时开启吗?

2024-01-03 399 views
0

同时开启http,和https,

app.conf: httpport = 8080 HTTPSPort = 8888 enablehttp = true EnableHTTPS = true EnableHttpTLS = true

运行: bee run

就出错: ListenAndServe: listen tcp :8888: bind: address already in use

单独运行http,或https都没问题,同时开htt和https就报错

回答

1

可以,你的错误提示你的8888端口已经被占用了啊

6

mac 一直无法同时启动,linux下一定几率无法同时启动,不知为何,很明确不是其他程序端口占用了。

4

我想问下, 你这个问题解决了吗? @ywolf

6

@ywolf 提示bind: address already in use的话是指端口已经占用。可以先用指令检查一下。如果还启动失败,建议把log贴上来分析

5

可以很确定的说, 端口肯定没被使用. 其次在哪里可以看更详细的log? image

4

问题初步锁定在beego的app.go文件中 if BConfig.Listen.EnableHTTPS { go func() { time.Sleep(1000 * time.Microsecond) if BConfig.Listen.HTTPSPort != 0 { app.Server.Addr = fmt.Sprintf("%s:%d", BConfig.Listen.HTTPSAddr, BConfig.Listen.HTTPSPort) } else if BConfig.Listen.EnableHTTP { BeeLogger.Info("Start https server error, confict with http.Please reset https port") return } logs.Info("https server Running on https://%s", app.Server.Addr) if err := app.Server.ListenAndServeTLS(BConfig.Listen.HTTPSCertFile, BConfig.Listen.HTTPSKeyFile); err != nil { logs.Critical("ListenAndServeTLS: ", err) time.Sleep(100 * time.Microsecond) endRunning <- true } }() } 这里有一个睡眠时间, 默认为20Millisecond 这个时间太短了, 我放到200Millisecond的时候, 报错频率明显下降 我把时间放到 1000* Millisecond,报错频率为0了, (测试样本不足, 大概重启了20遍, 没有出现报错)