file: http.go
package main import( "http" "log" "os" ) 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.Println(err) os.Exit(1) } }
enable mod_proxy, mod_proxy_http and mod_rewrite for your apache
sudo a2enmod proxy sudo a2enmod proxy_http sudo a2enmod rewrite sudo service apache2 restart
/etc/apache2/sites-available/gowebsite
<VirtualHost *:80> ServerAdmin test@gmail.com ServerName www.example.com ServerAlias example.com DocumentRoot /var/www <Directory /> Options FollowSymLinks AllowOverride None </Directory> <Directory /var/www/> Options Indexes FollowSymLinks MultiViews AllowOverride None Order allow,deny allow from all RewriteEngine on RewriteRule ^(.*)$ http://localhost:8080/$1 [P,L] </Directory> </VirtualHost>
sudo a2ensite gowebsite sudo service apache2 restart