亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

Beego如何支持HTTPS

Beego如何支持HTTPS

Go
慕工程0101907 2023-05-08 15:29:41
我想讓我的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


查看完整回答
反對 回復 2023-05-08
  • 1 回答
  • 0 關注
  • 201 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號