---
title: Deploying Rails 7 application with Nginx and Passenger
url: https://calvin.my/posts/deploying-rails-7-application-with-nginx-and-passenger
published: 2024-06-23
updated: 2026-09-17
category: Operations
tags:
- Rails
- Nginx
- Passenger
summary: This guide outlines deploying a Rails 7 application on Ubuntu 22.04 with Nginx and Phusion Passenger, noting that Passenger does not yet officially support Ubuntu 24.04. It covers preparing the server, installing required development dependencies, Nginx, Ruby through rbenv, Passenger, and SSL certificates. It then explains configuring the application site, linking Nginx settings, selecting the correct Ruby runtime, verifying Passenger, and optionally adding Node, Supervisor, log rotation, and ImageMagick.
---

# Deploying Rails 7 application with Nginx and Passenger

## Part 1: Installation

This deployment is done in Ubuntu 22.04 as Passenger has not officially supported 24.04 at this point in time.

1. Launch a new instance, and perform an update if there is one.

   ```bash
   sudo apt update
   sudo apt upgrade
   ```

2. Set the timezone if needed.

   ```bash
   sudo timedatectl set-timezone Asia/Kuala_Lumpur
   ```

3. Generate identity (Whitelist your repository with the public key if needed)

   ```bash
   ssh-keygen
   ```

4. Install the necessary tools

   ```bash
   sudo apt-get install git-core zlib1g-dev build-essential libssl-dev libreadline-dev libyaml-dev libxml2-dev libxslt1-dev libcurl4-openssl-dev software-properties-common libffi-dev mysql-client libmysqlclient-dev
   ```

5. Install nginx

   ```bash
   sudo apt install nginx -y
   ```

6. Install rbenv and ruby-build

   ```bash
   git clone https://github.com/rbenv/rbenv.git ~/.rbenv
   ~/.rbenv/bin/rbenv init
   git clone https://github.com/rbenv/ruby-build.git "$(rbenv root)"/plugins/ruby-build
   ```

7. Install the intended Ruby version and make it global

   ```bash
   rbenv install 3.x.x
   rbenv global 3.x.x
   ```

8. Follow the [official guide](https://www.phusionpassenger.com/docs/advanced_guides/install_and_upgrade/nginx/install/) to install Passenger.
9. Follow the [official guide](https://certbot.eff.org/) to install certbot for Let's Encrypt.

## Part 2: Application

Clone your code, or setup Capistrano deployment

## Part 3: Setup Nginx & Passenger

1. Remove the default nginx site config

   ```bash
   sudo rm /etc/nginx/sites-available/default
   ```

2. Create your site config

   ```bash
   # /etc/nginx/sites-available/mysite
   server {
           server_name my.domain;
           passenger_enabled on;
           rails_env production;
           root /path/to/public;
           listen 80 default_server;
           listen [::]:80 default_server;
   }
   ```

3. Create a symlink of this config in the sites-enabled directory

   ```bash
   sudo ln -s /etc/nginx/sites-available/mysite mysite
   ```

4. Update the Passenger config to point to the correct Ruby.

   ```bash
   ### Begin automatically installed Phusion Passenger config snippet ###
   passenger_root /usr/lib/ruby/vendor_ruby/phusion_passenger/locations.ini;
   passenger_ruby /home/ubuntu/.rbenv/shims/ruby;

   passenger_instance_registry_dir /var/run/passenger-instreg;

   ### End automatically installed Phusion Passenger config snippet ###

   passenger_preload_bundler on;
   ```

5. Start the Nginx server

   ```bash
   sudo service nginx start
   ```

6. Check passenger status

   ```bash
   passenger-status
   ```

7. Install SSL Cert using Certbot

   ```bash
   sudo certbot --nginx
   ```

## Part 4: Optional Steps

1. Install node

   ```bash
   sudo apt install nodejs
   ```

2. Install supervisor

   ```bash
   sudo apt install supervisor
   ```

3. Install logrotate

   ```bash
   sudo apt install logrotate
   ```

4. Install imagemagick

   ```bash
   sudo apt install imagemagick
   ```
