Erik Rothoff
Erik Rothoff

Reputation: 5123

Running a Go webserver behind Phusion Passenger

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?

Upvotes: 1

Views: 419

Answers (2)

Michael
Michael

Reputation: 735

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.

Upvotes: 2

hobbs
hobbs

Reputation: 239861

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.

Upvotes: 3

Related Questions