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 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog