在Phusion Passenger后面运行Go Web服务器

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

Running a Go webserver behind Phusion Passenger

问题

Phusion Passenger在Web服务器后面运行Web应用程序方面有着很好的生态系统。我在Ruby和Node.js应用程序中有使用经验。现在我重写了一个使用Go的Web服务,并且是时候部署它了。将Passenger+Nginx放在Go Web服务器(使用net/http)前面似乎是很自然的选择。在搜索中,似乎没有人尝试过这样做,也没有在任何地方提到过这个问题...

我似乎找不到一个配置选项来附加一个自定义的二进制文件,而不是使用passenger_ruby/passenger_node等。

我可以(应该)使用Phusion Passenger来运行使用go build创建的二进制文件吗?

英文:

Phusion Passenger has a great ecosystem for running webapps behind a webserver. I have experience with it from Ruby and Node.js apps. Now I rewrote a webservice to use Go, and it's time to deploy it. It seems natural to put Passenger+Nginx in front of the go webserver (using net/http). Searching around it seems that nobody has tried this, or asked about this anywhere...

I can't seem to find a configuration option to attach a custom binary, instead of passenger_ruby/passenger_node etc.

Can (should?) I use Phusion Passenger to run my binary created using go build?

答案1

得分: 3

不,你不能。Passenger实际上不使用HTTP内部协议;它使用一种自定义协议(类似于FastCGI或SCGI,但与两者都不兼容)与你的应用程序进行通信,并需要应用程序中的自己的代码来管理和分派请求。他们不提供针对Go的这种支持代码。

英文:

No, you can't. Passenger doesn't actually use HTTP internally; it uses a custom protocol (like FastCGI or SCGI but incompatible with both) to communicate with your app and requires its own code in the application for management and dispatching requests. They don't provide such support code for Go.

答案2

得分: 2

这是现在可以实现的,Passenger 6已经添加了通用语言支持。您可以在这里找到教程:https://www.phusionpassenger.com/docs/advanced_guides/gls/go.html

基本上:

  1. 编译您的Go程序并将二进制文件放在方便的位置。应用程序需要接受配置以选择要在哪个端口上运行。
  2. passenger start --app-start-command 'env PORT=$PORT ./main',假设main是您的程序名称。

Passenger将尝试告诉应用程序要在哪个端口上启动,以便可以使用端口80/443。

英文:

This is actually possible now, Passenger 6 has added generic language support. You can find the tutorial here: https://www.phusionpassenger.com/docs/advanced_guides/gls/go.html

Basically:

  1. Compile your Go program and put the binary somewhere convenient. The application needs to accept configuration to choose what port to run on.
  2. passenger start --app-start-command 'env PORT=$PORT ./main' assuming main is your program name.

Passenger will try to tell the application what port to start on so that it can have port 80/443.

huangapple
  • 本文由 发表于 2016年1月3日 00:30:53
  • 转载请务必保留本文链接:https://go.coder-hub.com/34568073.html
匿名

发表评论

匿名网友

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

确定