Run go code with Apache..

649 views
Skip to first unread message

sasth...@gmail.com

unread,
May 1, 2014, 3:48:35 AM5/1/14
to golan...@googlegroups.com
I am new of go language. I have an go code for creating web Application. 
Is this possible to integrate go with apache server.
Is there any procedure / configurations to done this..?

Please reply me your solution on this pulse thread.....

Tamás Gulácsi

unread,
May 1, 2014, 7:53:55 AM5/1/14
to golan...@googlegroups.com
Yes, for example by writing a Go http server (see net/http) and using Apache as a reverse proxy.

Christoph Hack

unread,
May 1, 2014, 7:59:14 AM5/1/14
to golan...@googlegroups.com
Hi Kali!

Go´s http package comes with its own web server that performs really well. It's stable, handles many concurrent requests, has good crypto support and good support for HTTP/1.1 (including websockets and stuff like that). You usually don't want an Apache in front of it. But if you really do, you can use the Apache module "mod_proxy" in order to forward request to the Go webserver of your app. Alternatively, you could also use mod_fcgi and Go's fcgi package, but I guess the first solution is more flexible / robust.

I've done it the other way round. A small Go program (about 200 LOC) does some request dispatching based on host names, url paths, etc. (using http.ServeMux), serves static content (using http.FileServer) and forwards most of the other requests to other Go applications running on different ports as separate processes (using httputil.ReverseProxy). Some of my projects are still written in Python and are powered by Apache + mod_wsgi at the moment. My small Go program also forwards some requests to  them (also using httputil.ReverseProxy).

-christoph

Kelsey Hightower

unread,
May 1, 2014, 11:34:28 AM5/1/14
to golan...@googlegroups.com
Here is a great write up for using Apache as a reverse proxy:
https://www.digitalocean.com/community/articles/how-to-use-apache-http-server-as-reverse-proxy-using-mod_proxy-extension

The ProxyPass statements should point to your Go application. For example, if your application lives on the same box as Apache listening on port 8080 you might do something like this:


There is really nothing special you need to do in order to front Go applications with Apache. I'm assuming you prefer to use Apache for things like rate-limiting, authentication, and maybe SSL termination to keep your Go application as simple as possible. Valid use case to me.
Reply all
Reply to author
Forward
0 new messages