Go vs Apache, or both?

Hello,
I am getting ready to start developing a discord bot, and am thinking about using golang as discord has a go package with all the api hooks etc… I have been looking on google and YouTube for some information regarding running a go server alongside my servers current Apache install. So far i haven’t come up with anything.

Keep in mind I’ve only just now started looking at go so whether or not this is possible or even recommended I have no idea.

Thanks in advance for your help.

It is certainly possible. I see these options:

  • Write your Go server just as you would do when there was no Apache running. Have it listen on a port other than 80. Then configure Apache as an HTTP proxy for the Go server.
  • Write your Go server as a FastCGI service for Apache.
  • Use different (sub-)domains for Apache and for the Go server. (E.g., “mydomain.com” routes to Apache and “discord.mydomain.com” routes to the Go server.)
1 Like

a short example. let say you have example.com domain served by apache on port 80. probably you also have a bind server so you can add in the db.example.com file a CNAME (or A) record like

goapp IN CNAME example.com.

so, your apache will serve now goapp.example.com an also example.com both on port 80. next, make a virtual host in /etc/apache/sites-available

<VirtualHost *:80>
        ServerAdmin admin@example.com

        ServerName goapp.example.com

        Redirect "/" "http://goapp.example.com:8081"
</VirtualHost>

enable, this in with a symbolic link in /etc/apache/sites-enabled, compile with run your go application on port 8081. you can run your go application with no root rights.

now, if you will access goapp.example.com you will be redirect to goapp.example.com:8081
:blush:

As a proxy solution, that is far more flexible than working with redirect I strongly recommend to use nginx or haproxy, but apache.

location /godoc {
    proxy_pass http://localhost:6060/;
} # for nginx
2 Likes

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