在 Go 的网络服务器前使用 Nginx 有什么好处? [英] What are the benefits of using Nginx in front of a webserver for Go?

查看:20
本文介绍了在 Go 的网络服务器前使用 Nginx 有什么好处?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写一些返回 JSON 数据的网络服务,这些数据有很多用户.

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

与仅使用 go http 服务器相比,在我的服务器前端使用 Nginx 有什么好处?

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

推荐答案

视情况而定.

开箱即用,将 nginx 放在前面作为反向代理会给你:

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

  • 访问日志
  • 错误日志
  • 轻松终止 SSL
  • SPDY 支持
  • gzip 支持
  • 在几行中为某些路由设置 HTTP 标头的简单方法
  • 非常快的静态资产服务(如果您在 S3/等平台上提供服务,这不是那么重要)

Go HTTP 服务器非常好,但是您需要重新发明轮子来做其中一些事情(这很好:它并不意味着对每个人都适用).

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).

我一直发现将 nginx 放在前面更容易——这是它的优点——让它做网络服务器"的事情.我的 Go 应用程序执行应用程序的工作,并且只有最少的标题/等.它需要.不要认为把 nginx 放在前面是一件坏事".

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.

这篇关于在 Go 的网络服务器前使用 Nginx 有什么好处?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆