Skip to main content
This guide shows you how to replace the Puma web server which runs your Rails application with nginx and Phusion Passenger. This may be useful if you need functionality that nginx and/or Passenger provide, such as reverse proxying or hosting multiple applications.

Replacing the Dockerfile

When you previously ran fly launch you were provided with a Dockerfile that was used to package your application. This Dockerfile provided reasonable defaults. One of those defaults was to choose the Puma web server. This is the same default that Rails provides for new applications. This Dockerfile can be customized or replaced to meet your needs. This guide will show you how to replace the Dockerfile with one that chooses Phusion Passenger. The new Dockerfile will make use of the phusion/passenger-full image. To get started, replace your Dockerfile with the following:
As promised, the passenger-full image that the Phusion team provides makes your Dockerfile considerably smaller, but there remains more work to be done as you still need to configure nginx. We do that next.

Configuring nginx

The Dockerfile above contains three ADD commands. These copy configuration files to the image. The first two files configure nginx. Place all three files in a config/fly directory. We start with config/fly/rails.conf:
The servername doesn’t particularly matter, but you can set it to the name of the machine your application will be deployed to. The only real customization required is to select the version of Ruby desired. Next we need to identify what environment variables will be used by the application. See the passenger documentation for more details. We do that by placing the following into config/fly/envvars.conf:
The above are commonly used variables, feel free to adjust as you see fit.

Enabling swap

See swap_size_mb for configuring for deploys.

Deployment

That’s it. As always you deploy your application via fly deploy and can open it via fly apps open. Everything else remains the same. You can use your same Postgre database, redis data store, and any other secrets you may have set. Both Puma and Passenger are excellent choices for application servers for your Rails application, so you normally wouldn’t have a need to replace one with the other. Further configuration likely is required to unlock specific features of nginx or passenger for your particular needs. The above is only intended as an initial configuration to get you started. You have full control over what is installed on your machine and how both nginx and passenger are configured. The sky’s the limit on what you can achieve with these instructions!