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
  - url: /.*
    script: auto
    secure: always
    redirect_http_response_code: '301'
  - url: .*
    script: auto
  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 visionmaster启动失败,提示为“机器不满足授权而被禁用”
  • ¥50 用logisim设计16位单时钟周期cpu
  • ¥15 IDEA中圈复杂度如何具体设置
  • ¥50 labview采集不了数据
  • ¥15 请上面代码做什么处理或什么混淆
  • ¥15 英雄联盟自定义房间置顶
  • ¥15 W5500网线插上无反应
  • ¥15 如何用字典的Key,显示在WPF的xaml中
  • ¥15 weautomate读取Excel表格信息然后填写到网页一直报错,如何解决?
  • ¥15 C#如何在Webview2中获取网页验证码