I found a web page that tells how to make Go work with Apache, when you are using a virtual host file:
I can make a simple Go test server work *without* Apache, but I can't make the same test program work with Apache on CentOS 7 using Amazon EC2 instance.
So, I'm curious, what is the normal way of using Go with Apache? Do I need to move the Go program to cgi-bin folder or make changes to the Apache configuration files and what kind of changes? For me, it's surprisingly difficult to find a simple example for Go + Apache. ;)
I probably don't need this kind of file at /etc/httpd/sites-available/[mywebsite]:
#######################################################
<VirtualHost *:80>
ServerName [mywebsite]
ServerAlias [mywebsite]
DocumentRoot /var/www/[mywebsite]/public_html
# ErrorLog /var/www/[mywebsite]/error.log
# CustomLog /var/www/[mywebsite]/requests.log combined
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
<Directory /var/www/[mywebsite]>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all
RewriteEngine on
</Directory>
</VirtualHost>
#######################################################
The simple Go test server program:
// ****************************************************
package main
import (
"net/http"
"log"
)
const resp = `<html>
<head>
<title>Simple Web App</title>
</head>
<body>
<h1>Simple Web App</h1>
<p>Hello World!</p>
</body>
</html>`
func handler( w http.ResponseWriter,
r *http.Request ) {
w.Write([]byte(resp))
}
func main() {
http.HandleFunc( "/", handler )
err := http.ListenAndServe( ":8080", nil )
if err != nil {
log.Fatal( "ListenAndServe: ", err.Error() )
}
}
// ****************************************************