[web] why my server do not start on ubuntu?


(ext) #1

Good day

Please tell me what I’m doing wrong, other programs run like this.

I compiled the sources into a binary file and run the server on ubuntu

chmod 777 webserver_linux_amd64
nohup /root/webserver_linux_amd64&

but not working…

in local machine this code work fine

const (
CONN_HOST = "localhost"
CONN_PORT = "8089"
)

err = http.ListenAndServe(CONN_HOST+":"+CONN_PORT, nil)

maybe need to change CONN_HOST? How to define a host variable correctly for server? Or is there another method? or what could be the problem here?


(Ashish Shekar) #2

Server as in like for AWS instance?

Edit:

If yes use http.ListenAndServe(":"+CONN_PORT, nil)


(Norbert Melzer) #3

Does the server not run? If so, what error do you get?

Or is it that you can not connect to it? Binding localhost:8089 will only accept connections made through the loopback device. Usually you want to bind an IP that exist on a device that is routable from the outside world or 0.0.0.0/:: to bind all IPs.


(ext) #4

I entered the server ip address instead of localhost and it all worked, maybe there is some function how can I do this to find out the server address?


(ext) #5

I will try this ,thanks


(Norbert Melzer) #6

Yes, you can find out ybout all available network interfaces using net.Interfaces(), then you can iterate over them and use net.interface.Addrs to get their IP addresses.

After that you’ll have a list of IP addresses, but you wont know which of them is publicly available.

The IP to bind to is usually given as a configuration option or simply 0.0.0.0 or :: are used to bind to all available IP addresses.

Due to security reasons, I’d always bind to a single IP only once the software goes live.

I’m less strict about this when the host itself is not publicly available but only accessible through a loadbalancer/reverse proxy.