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?