我想让我的beego网站支持https。还有一个帖子Beego 和 Https。我尝试使用该方法启用 chrome 设置chrome://flags/#allow-insecure-localhost或使用 Microsoft Edge 打开 url。还是显示This site can't be reached。环境go 版本 go1.10 windows/amd64条款:1.10.1我的步骤是:将 googleapis.cer 安装到我的 Windows 10 计算机上。将 googleapis.cer 和 googleapis.keyfile 复制到D:\Go_workspace\src\myproject编辑D:\Go_workspace\src\myproject\conf\app.confappname = myprojectrunmode = prod[dev]httpaddr = "127.0.0.1"HTTPPort = 9100[prod]httpaddr = "127.0.0.1"HTTPSPort = 9099httpsaddr = "127.0.0.1"EnableHTTPS = trueEnableHttpTLS = trueHTTPSCertFile = "googleapis.cer"HTTPSKeyFile = "googleapis.key" [test]HTTPSPort = 9099使用蜜蜂工具命令运行我的项目....\bin\bee run我收到以下消息并显示消息This site can't be reached when I go to URL https://127.0.0.1:9099 :2018/11/09 10:07:56.251 [I] [asm_amd64.s:2361] http server Running on http://127.0.0.1:80802018/11/09 10:07:56.253 [I] [asm_amd64.s:2361] https server Running on https://127.0.0.1:90992018/11/09 10:07:56.293 [C] [asm_amd64.s:2361] ListenAndServeTLS: listen tcp 127.0.0.1:9099: bind: Only one usage of each socket address (protocol/network address/port) is normally permitted.有谁知道如何解决这个问题?谢谢
1 回答
料青山看我应如是
TA贡献1772条经验 获得超8个赞
可能存在竞争条件,beego这使得同时运行 HTTP 和 HTTPS 时断断续续。你可以在app.go
if BConfig.Listen.EnableHTTPS || BConfig.Listen.EnableMutualHTTPS {
go func() {
//...
app.Server.Addr = // the Addr is set to the value of HTTPS addr
// ListenAndServeTLS()
}()
}
if BConfig.Listen.EnableHTTP {
go func() {
app.Server.Addr = addr // the Addr is set to the valu of HTTP addr
// ListenAndServe()
}()
}
如您所见,它Server.Addr设置在不同的 goroutine 上,这是一场数据竞争。
所以我建议你只在 HTTPS 上运行你的应用程序,除非你想给beego自己打补丁。
例如在你的 app.conf 中:
EnableHTTP = false
EnableHTTPS = true
- 1 回答
- 0 关注
- 138 浏览
添加回答
举报
0/150
提交
取消