Skip to content

Instantly share code, notes, and snippets.

@hmasila
Last active January 28, 2025 21:32
Show Gist options
  • Save hmasila/21347e56eb779259ea216a74a37840af to your computer and use it in GitHub Desktop.
Save hmasila/21347e56eb779259ea216a74a37840af to your computer and use it in GitHub Desktop.

Install nginx

$ sudo apt-get install nginx

$ sudo apt-get install -y dirmngr gnupg apt-transport-https ca-certificates curl

$ curl https://oss-binaries.phusionpassenger.com/auto-software-signing-gpg-key.txt | gpg --dearmor | sudo tee /etc/apt/trusted.gpg.d/phusion.gpg >/dev/null

Add APT repository

$ sudo sh -c 'echo deb https://oss-binaries.phusionpassenger.com/apt/passenger jammy main > /etc/apt/sources.list.d/passenger.list'

$ sudo apt-get update

Install Passenger + Nginx module

$ sudo apt-get install -y libnginx-mod-http-passenger

Edit Passenger Conf

$ sudo vi /etc/nginx/conf.d/mod-http-passenger.conf

passenger_root /usr/lib/ruby/vendor_ruby/phusion_passenger/locations.ini;
passenger_ruby /home/deploy/.rbenv/shims/ruby;

Set user to deploy in nginx.conf

$ sudo vi /etc/nginx/nginx.conf

Create sites-available nginx file for your domain

$ sudo vi /etc/nginx/sites-available/myapp

server {
        listen 80 default_server;
        listen [::]:80 default_server;
        server_name my.ip.address;

        root /home/deploy/myapp/current/public;

        # Add index.php to the list if you are using PHP


        passenger_enabled on;
        passenger_ruby /home/deploy/.rbenv/shims/ruby;
        passenger_app_env staging;
        client_max_body_size 800M;
}

Symlink sites-available with sites-enabled

$ sudo ln -s /etc/nginx/sites-available/myapp /etc/nginx/sites-enabled/

Check if nginx is correctly configured

$ sudo nginx -t

Start Nginx

$ sudo service nginx start

Validate Passenger install

$ sudo /usr/bin/passenger-config validate-install

Check whether passenger has started nginx core process

$ sudo /usr/sbin/passenger-memory-stats

Start passenger

$ passenger-config restart-app

If you get an eeror that passenger is not serving any applications, go to the browser and paste the url again. Do not reload, it won't work. You have to enter the url afresh

@imuchene
Copy link

There are a few things missing for this gist to work:

  • Ruby must be installed via rbenv
  • A 'deploy' account must already exist on the system
  • The app must already be copied to the 'myapp' directory in the home directory of the deploy account (and all dependencies installed)

@hmasila
Copy link
Author

hmasila commented Sep 10, 2024

@imuchene This gist is specific for Passenger and Nginx installation as the title suggests

@imuchene
Copy link

For a rails deployment, it's better if all this information is in one place, rather than scattered in a bunch of gists. I'd recommend using an infrastructure automation tool such as ansible or chef.

@hmasila
Copy link
Author

hmasila commented Sep 12, 2024

Thanks for the suggestions. However, these gists are for personal use and they describe what they're intended to do. I'll go ahead and make them private to avoid any further confusion.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment