在生产环境中部署Go/Golang的REST Web API。

huangapple go评论120阅读模式
英文:

Deploy Go/Golang REST Web API on production

问题

我正在为一个移动应用编写后端Web API。它应该支持HTTPS。我在.NET方面有很多经验,但是这次我想使用Go/Golang。我已经准备好了一个示例服务,现在我需要确保它可以投入生产使用。
在.NET中,我会使用IIS,但是我不知道在Go中应该选择什么好方法。
我应该使用nginx作为反向代理,还是最好使用FastCGI?如何确保我的Go应用程序在系统重启后能够正常运行?我应该使用upstart或类似的东西吗?

英文:

I am writing a backend web api for a mobile app. It should support HTTPS. Most of my experience in .NET, but for this one I want to use Go/Golang. I have a sample service ready, now I need to make sure that it is production ready.
In .NET I will just use IIS, but I have no clue what would be a good approach for Go.
Should I have nginx as reverse proxy, or I better use FastCGI ? And how to make sure that my go app is up and will run on system reboot ? should I use upstart or something similar ?

答案1

得分: 1

我一直在使用Nginx FastCGI和Go webservice,它们很好地配合使用。设置起来并不比HTTP反向代理更困难,只是需要学习如何操作。原则上性能应该更好,但我没有测量数据来证明这个猜测。我的Web服务可以在HTTP模式和FastCGI模式下工作(一次只能选择其中一种),所以我想我应该进行一些基准测试(自己提醒一下!)。

如果你想要正确的系统启动(你应该这样做),你需要学习如何编写初始化脚本。有时候我会作弊,使用其他人为类似应用编写的现有工作脚本,并对其进行自定义以适应我的应用。

英文:

I've been using Nginx FastCGI with a Go webservice - they work well together. It's no harder to set up than HTTP reverse proxying - except for having to learn how to do it. The performance ought in principle to be a lot better, but I have no measurements to justify that hunch. My web service can work in both HTTP mode and FastCGI mode (one or other at a time), so I suppose I ought to do some benchmarking (note to self!).

If you want proper system startup (and you should), you need to learn how init scripts work. I sometimes cheat and start with an existing working script someone else wrote for a similar application and customise it to work with mine.

答案2

得分: 0

我已经将您的请求翻译成中文:

我已经将nginx用作我的Go项目的反向代理。我发现在nginx中设置有用的服务器设置,如TLS、压缩等,比作为纯Go服务器要容易得多。

在服务器重新启动时保持其运行是一个更复杂的问题。我建议学习如何为您的服务器的初始化守护程序编写脚本/其他方式,并按照那种方式进行操作。

英文:

I've used nginx as a reverse proxy for my Go projects. I've found that it's a lot easier to set up useful server settings such as TLS, compression, etc., in nginx rather than as a pure Go server.

Keeping it alive on server reboot is a more complicated question. I would suggest learning how to write a script/whatever for your server's init daemon and just doing it that way.

huangapple
  • 本文由 发表于 2014年11月22日 23:00:39
  • 转载请务必保留本文链接:https://go.coder-hub.com/27078772.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定