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.
- Launch a new instance, and perform an update if there is one.
sudo apt update sudo apt upgrade
- Set the timezone if needed.
sudo timedatectl set-timezone Asia/Kuala_Lumpur
- Generate identity (Whitelist your repository with the public key if needed)
ssh-keygen
- Install the necessary tools
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
- Install nginx
sudo apt install nginx -y
- Install rbenv and ruby-build
https://github.com/rbenv/rbenv 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
- Install the intended Ruby version and make it global
rbenv install 3.x.x rbenv global 3.x.x
- Follow the official guide to install Passenger.
- Follow the official guide to install certbot for Let's Encrypt.
Part 2: Application
Clone your code, or setup Capistrano deployment
Part 3: Setup Nginx & Passenger
- Remove the default nginx site config
sudo rm /etc/nginx/sites-available/default
- Create your site config
# /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; }
- Create a symlink of this config in the sites-enabled directory
sudo ln -s /etc/nginx/sites-available/mysite mysite
- Update the Passenger config to point to the correct Ruby.
### 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;
- Start the Nginx server
sudo service nginx start
- Check passenger status
passenger-status
- Install SSL Cert using Certbot
sudo certbot --nginx
Part 4: Optional Steps
- Install node
sudo apt install nodejs
AI Summary
gpt-4o-2024-05-13
2024-07-16 00:41:00
This guide explains how to deploy a Rails 7 application using Nginx and Passenger on Ubuntu 22.04. It covers installation steps, application setup, Nginx and Passenger configuration, and optional steps such as installing Node. Key steps include updating the server, installing necessary tools, configuring Nginx, and setting up SSL with Certbot.
Chrome On-device AI
2024-10-04 21:58:14
Share Article