Search code examples
gooracle-cloud-infrastructureport80

Oracle cloud - golang http server not working on port 80


I have a golang http server which is supposed to listen on port 80.

My problem is:

The program compiles normally but exit without listening. When I change the port to 8080 everything works normally and I can access my web page.

  • I am using Ubuntu as my operating system.
  • I added an Ingress Rules which allows port 80

I don't understand why my server is not listening on port 80 but listening on all other ports.

Thank you for your help.

package main

import (
    "fmt"
    "net/http"
)

func hello(w http.ResponseWriter, r *http.Request) {
    fmt.Fprintf(w, "<p>Hello world!</p>")
}

func main() {
        http.HandleFunc("/", hello)
        http.ListenAndServe(":80", nil)
}

Solution

  • Check for the error

    err := http.ListenAndServe(":80", nil)
    fmt.Println(err)
    

    output on my local is this, but it can have other reason

    listen tcp :80: bind: permission denied