Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 810
Daniele B Avatar asked Jul 21 '13 20:07

Daniele B


People also ask

Can we use nginx as web server?

Introduction. Apache and Nginx are two popular open-source web servers often used with PHP. It can be useful to run both of them on the same virtual machine when hosting multiple websites which have varied requirements.

How does nginx web server work?

NGINX is a web server that also acts as an email proxy, reverse proxy, and load balancer. The software's structure is asynchronous and event-driven; which enables the processing of many requests at the same time. NGINX is highly scalable as well, meaning that its service grows along with its clients' traffic.


1 Answers

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.

like image 100
elithrar Avatar answered Sep 30 '22 22:09

elithrar