猿问

如何在 https 中以生产模式运行 Beego 二进制文件?

我的 Go 应用程序在 https 模式下运行。我正在使用 Beego 框架。我的 app.conf 看起来像:


appname = myproject

httpsport = 10555

httpport = 8082

runmode = prod

EnableHTTP = false

EnableHTTPS = true

HTTPSCertFile = server.crt

HTTPSKeyFile = server.key

copyrequestbody = true

当我在本地运行它时,它运行得非常好,GoLang 服务器在 10555 上使用 https 运行。但是当我构建二进制文件并尝试在另一台服务器上运行它时,它只尝试在 http 端口 8082 上运行。


守着一只汪
浏览 106回答 2
2回答

鸿蒙传说

I used it like this :----app.config{appname = firstapp# httpport = 8080runmode = dev //when in test comment this line#runmode = test //when in test uncomment this lineautorender = falsecopyrequestbody = trueEnableDocs = true[dev]httpport = 8080# [prod]# httpport = 8088[test]httpport = 8888}-----main.gofunc init() {// 1 - Enable debugorm.Debug = false// 2 - Register object with Beego ORMorm.RegisterModel(new(models.User), new(models.Role), new(models.Function), new(models.Role_function))//orm.RegisterModel(new(models.User), new(models.Role))if beego.BConfig.RunMode == "dev" {    // 3 - Fetch database properties stored as YAML, decode secrets    connStr, err := util.FetchYAMLDEV()    if err != nil {        log.Fatalf("error: %v", err)    }    // 4 - Register posgres driver and db    orm.RegisterDriver("postgres", orm.DRPostgres)    orm.RegisterDataBase("default", "postgres", connStr)    // 5 - Create and load DB with sample data, can comment after initial load    models.CreateDb()    models.LoadDb()}if beego.BConfig.RunMode == "test" {    // 3 - Fetch database properties stored as YAML, decode secrets    fmt.Println("in test runmofe")    connStr, err := util.FetchYAMLTEST()    if err != nil {        log.Fatalf("error: %v", err)    }    // 4 - Register posgres driver and db    orm.RegisterDriver("postgres", orm.DRPostgres)    orm.RegisterDataBase("default", "postgres", connStr)    // 5 - Create and load DB with sample data, can comment after initial load    models.CreateDb()    models.LoadDb()}}----util.FetchYAML.gopackage utilimport (    "fmt"    "os"    "log"    "github.com/joho/godotenv")func goDotEnvVariable(key string) string {// load .env fileerr := godotenv.Load(".env")if err != nil {    log.Fatalf("Error loading .env file")}return os.Getenv(key)}func FetchYAMLDEV() (string, error) {user := goDotEnvVariable("user_dev")dbname := goDotEnvVariable("dbname_dev")password := goDotEnvVariable("password_dev")host := goDotEnvVariable("host_dev")port := goDotEnvVariable("port_dev")return fmt.Sprintf("user=%s dbname=%s password=%s host=%s port=%s sslmode=disable",    user, dbname, password, host, port), nil}func FetchYAMLTEST() (string, error) {user := goDotEnvVariable("user")dbname := goDotEnvVariable("dbname")password := goDotEnvVariable("password")host := goDotEnvVariable("host")port := goDotEnvVariable("port")return fmt.Sprintf("user=%s dbname=%s password=%s host=%s port=%s sslmode=disable",    user, dbname, password, host, port), nil}----.env ACCESS_SECRET = vjhbjhjhuser = postgresdbname = golangpassword = passwordport = 5432host = localhostsslmode = disableuser_dev = devuserdbname_dev = defdbnamepassword_dev = devpassport_dev = 5432host_dev = devhostsslmode_dev = disableuser_test = testuserdbname_test = testdbnamepassword_test = testpassport_test = 5432host_test = testhostsslmode_test = disable

慕无忌1623718

我认为这意味着 httpport 是服务器/本地服务器中的一个端口,与 http 或 https 需要什么不同。您可以对该环境使用拆分方法,例如用于环境httpport=8082暂存服务器的 development.conf () 和用于环境httpport=10555生产服务器的 production.conf (),然后您可以在部署时将环境替换为 app.conf
随时随地看视频慕课网APP

相关分类

Go
我要回答