dougao7801 2019-09-02 09:43
浏览 185
已采纳

为什么应用引擎会忽略app.yaml中的PORT env变量

I am trying to migrate from Go 1.9 to Go 1.11. I copied the main function from the migration document

This is my app.yaml

runtime: go111
env: standard
instance_class: F1
handlers:
  - url: /.*
    script: auto
    secure: always
    redirect_http_response_code: '301'
  - url: .*
    script: auto
env_variables:
  PORT: '443'

This is my main function

func main() {
    http.HandleFunc("/demo", demoHandler)

    port := os.Getenv("PORT")
    if port == "" {
            port = "443"
            syslog.Printf("Defaulting to port %s", port)
    }

    syslog.Printf("Listening on port %s", port)
    syslog.Fatal(http.ListenAndServe(fmt.Sprintf(":%s", port), nil))
}

My application needs to run on port 443 with HTTPS. However, after deployment, the application doesn't respond. I checked the logs, and it says "Listening on port 8081". I don't understand why it takes 8081 instead of 443. Where is this 8081 from?

If I hardcode the main function to use port 443. It gives me this in the logs "App is listening on port 443, it should instead listen on the port defined by the PORT environment variable. As a consequence, nginx cannot be started. Performance may be degraded. Please listen on the port defined by the PORT environment variable."

What do I miss here?

  • 写回答

1条回答 默认 最新

  • douzi6060 2019-09-02 09:51
    关注

    The PORT environment variable will be set by the AppEngine platform, you do not have to set it in your app.yaml config file. In fact, you can't even override it.

    See the list of environment variables set by the runtime.

    So just use the PORT env var as you do in your Go code, but remove it from your app.yaml config. You just have to start a non-HTTPS web server, the platform will provide HTTPS support for you.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 解决一个加好友限制问题 或者有好的方案
  • ¥15 关于#java#的问题,请各位专家解答!
  • ¥15 急matlab编程仿真二阶震荡系统
  • ¥20 TEC-9的数据通路实验
  • ¥15 ue5 .3之前好好的现在只要是激活关卡就会崩溃
  • ¥50 MATLAB实现圆柱体容器内球形颗粒堆积
  • ¥15 python如何将动态的多个子列表,拼接后进行集合的交集
  • ¥20 vitis-ai量化基于pytorch框架下的yolov5模型
  • ¥15 如何实现H5在QQ平台上的二次分享卡片效果?
  • ¥30 求解达问题(有红包)