我想让我的beego网站支持https。
还有一个帖子Beego and Https .我尝试使用该方法启用 chrome 设置 chrome://flags/#allow-insecure-localhost 或使用 Microsoft Edge 打开 url。仍然显示无法访问此站点。
环境
- 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.conf
appname = myproject runmode = prod [dev] httpaddr = "127.0.0.1" HTTPPort = 9100 [prod] httpaddr = "127.0.0.1" HTTPSPort = 9099 httpsaddr = "127.0.0.1" EnableHTTPS = true EnableHttpTLS = true HTTPSCertFile = "googleapis.cer" HTTPSKeyFile = "googleapis.key" [test] HTTPSPort = 9099
使用蜜蜂工具命令运行我的项目....\bin\bee run
当我转到 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:8080
2018/11/09 10:07:56.253 [I] [asm_amd64.s:2361] https server Running on https://127.0.0.1:9099
2018/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.
有谁知道如何解决这个问题?谢谢
最佳答案
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
关于go - Beego如何支持HTTPS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53219095/