如何在Beego中支持HTTPS

如何在Beego中支持HTTPS,go,https,beego,Go,Https,Beego,我希望我的beego网站支持https 还有一个帖子。我尝试使用该方法启用chrome设置chrome://flags/#allow-不安全的本地主机或使用Microsoft Edge打开url。仍然显示无法访问此站点 环境 go1.10版windows/amd64 比戈:1.10.1 我的步骤是: 将googleapis.cer安装到我的windows 10计算机上 将googleapis.cer和googleapis.keyfile复制到D:\Go\u workspace\src\my

我希望我的beego网站支持https

还有一个帖子。我尝试使用该方法启用chrome设置chrome://flags/#allow-不安全的本地主机或使用Microsoft Edge打开url。仍然显示无法访问此站点


环境

  • go1.10版windows/amd64
  • 比戈:1.10.1
我的步骤是:

  • 将googleapis.cer安装到我的windows 10计算机上
  • 将googleapis.cer和googleapis.keyfile复制到
    D:\Go\u workspace\src\myproject
  • 编辑
    D:\Go\u 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
    
  • 使用bee工具命令运行我的项目…\bin\bee Run

  • 我收到以下消息并显示消息当我转到URL时,无法访问此站点:


    有人知道如何解决这个问题吗?谢谢

    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
    本身

    e、 g.在app.conf中:

    EnableHTTP = false
    EnableHTTPS = true
    

    酷!这是工作。谢谢@ssemilla。但是我的网站仍然不安全,我需要使用全局可信的https证书。
    EnableHTTP = false
    EnableHTTPS = true