How to think when using a Go web server?

**Operating system:Debian
**OS version:10

I have done some tests with Go replacing both nginx and apache. In this site I am using the built in Go web server listening on port 80/443 on a Debian VPS without Virtualmin.

Now I am trying to translate this behavior to Virtualmin. But it seems that the nginx server is “taking over”. and not pointing to the Go server. I have placed the Go server in “public_html” but where should I put the executable?

The Go server is about 7MB and consist basically of a couple of lines:

http.HandleFunc(/, HelloServer)
http.ListenAndServe(:80, nil)

Any tip how to dismiss the nginx and point to the Go server is appreciatied.

The common best practice for app servers is to run them on some high port on localhost (e.g. 3000 or 5000 or 8080 are common choices) and proxy to them using a “real” web server. That’s probably the right thing for you, too. You probably do not want to “dismiss the nginx”, you probably want to move your app server to a local port and let nginx proxy outside requests to it for you.

Your server definitely should not go in public_html. That’s not what it’s for. public_html is what static HTML and executable PHP lives. Nothing else ever goes there (for security reasons, among others).

These aren’t Virtualmin questions, though. The advice I’m giving applies to pretty much all app servers using any language and is not specific to Virtualmin.

I quickly googled it for you. This looks reasonabe: How To Deploy a Go Web Application Using Nginx on Ubuntu 18.04 | DigitalOcean

Thank you for your input!

I have got this to work with Virtualmin by shutting off Nginx, BUT all domains points to the same Go executable, despite there are different contents. I interpret that this is hard to “redirect” to correct executable using Virtualmin without a “real” web server?

I also interpret that your suggestion is to use Nginx as proxy pointing to different ports?
And it is not possible for Virtualmin to run websites made in Go? Or Hugo?

Your mental model for how this is supposed to work is simply wrong. Virtualmin does what you’re asking, and by turning off nginx, you’ve broken it.

I told you how to solve the problem using common best practices.

1 Like

You have pointed me in a direction and I will follow your advice and have a look at nginx. Thanks.

This topic was automatically closed 8 days after the last reply. New replies are no longer allowed.