Go/Golang Share Instance

go get -u github.com/gorilla/mux
package mainimport (
"net/http"
"log"
"github.com/gorilla/mux"
)
func YourHandler(w http.ResponseWriter, r *http.Request) {
w.Write([]byte("One!\n"))
}
func main() {
r := mux.NewRouter()
// Routes consist of a path and a handler function.
r.HandleFunc("/", YourHandler)
// Bind to a port and pass our router in
log.Fatal(http.ListenAndServe(":8001", r))
}
package mainimport (
"net/http"
"log"
"github.com/gorilla/mux"
)
func YourHandler(w http.ResponseWriter, r *http.Request) {
w.Write([]byte("Two!\n"))
}
func main() {
r := mux.NewRouter()
// Routes consist of a path and a handler function.
r.HandleFunc("/", YourHandler)
// Bind to a port and pass our router in
log.Fatal(http.ListenAndServe(":8002", r))
}
tmux new -s one -d 'go run one.go'
tmux new -s two -d 'go run two.go'
sudo vim /etc/apache2/sites-available/one.oofnivek.com.conf
<VirtualHost *:80>
ProxyPreserveHost On
ProxyPass / http://localhost:8001/
ProxyPassReverse / http://localhost:8001/
ServerName one.oofnivek.com
</VirtualHost>
sudo vim /etc/apache2/sites-available/two.oofnivek.com.conf
<VirtualHost *:80>
ProxyPreserveHost On
ProxyPass / http://localhost:8002/
ProxyPassReverse / http://localhost:8002/
ServerName two.oofnivek.com
</VirtualHost>
sudo a2enmod proxy
sudo a2enmod proxy_http
sudo a2ensite one.oofnivek.com
sudo a2ensite two.oofnivek.com
sudo systemctl restart apache2

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Kevin FOO

Kevin FOO

15 Followers

A software engineer, a rock climbing, inline skating enthusiast, a husband, a father.