What are the benefits of using Nginx in front of a webserver for Go?

Daniele B picture Daniele B · Jul 21, 2013 · Viewed 34.6k times · Source

I am writing some webservices returning JSON data, which have lots of users.

What are the benefits of using Nginx in front my server compared to just using the go http server?

Answer

elithrar picture elithrar · Jul 22, 2013

It depends.

Out of the box, putting nginx in front as a reverse proxy is going to give you:

  • Access logs
  • Error logs
  • Easy SSL termination
  • SPDY support
  • gzip support
  • Easy ways to set HTTP headers for certain routes in a couple of lines
  • Very fast static asset serving (if you're serving off S3/etc. though, this isn't that relevant)

The Go HTTP server is very good, but you will need to reinvent the wheel to do some of these things (which is fine: it's not meant to be everything to everyone).

I've always found it easier to put nginx in front—which is what it is good at—and let it do the "web server" stuff. My Go application does the application stuff, and only the bare minimum of headers/etc. that it needs to. Don't look at putting nginx in front as a "bad" thing.