Deploy a new Rails application

There are different ways to deploy a Rails application.

Use Apache with Passenger

The most common way to deploy a Rails application is with Apache and Passenger. Follow the steps below:

  • Create a new file at installdir/httpd-vhosts.conf and fill it with the following content.

      <VirtualHost *:80>
          ServerName HOST_NAME
          DocumentRoot "installdir/APPNAME/public/"
          <Directory "installdir/APPNAME/public/">
              Options -MultiViews
              <IfVersion < 2.3 >
              Order allow,deny
              Allow from all
              <IfVersion >= 2.3>
              Require all granted
              RailsEnv development
              PassengerEnabled on
              PassengerAppRoot "installdir/APPNAME/"

    Remember to replace the HOST_NAME placeholder with the host name of your cloud server and the APPNAME placeholter with the correct directory for your Rails application.

  • Next, edit the installdir/apache2/conf/bitnami/bitnami-apps-vhosts.conf file and add the following line to the end of the file:

      Include installdir/httpd-vhosts.conf
  • Restart the Apache server.

      $ sudo installdir/ restart apache

After restarting Apache, the application should be accessible by browsing to http://localhost.

NOTE: Remember that you might need to adjust the permissions of your application directory and sub-directories to make them accessible to the user that the Apache server runs as - for example, with the command sudo chown bitnami:daemon installdir/APPNAME.

Use NGINX with Passenger

Follow these steps:

  • To configure NGINX to run at port 80, stop the Apache service. To do this, run the command below:

      $ sudo installdir/ stop apache
  • Once the Apache service has been stopped, modify the server configuration at installdir/nginx/conf/nginx.conf to be similar to this.

      server {
          listen 80;
          root installdir/APPNAME/public;
          passenger_enabled on;
          rails_env development;

    NOTE: The configuration above runs Passenger in development mode because, by default, Passenger starts in production mode which requires a secret to be configured. Using development mode bypasses this requirement and lets you test that everything is working correctly. When deploying to production, remember to change this value and provide a secret.

  • Before restarting NGINX to apply this configuration, disable Apache as shown below:

      $ sudo installdir/ stop apache
      $ sudo mv installdir/apache2/scripts/ installdir/apache2/scripts/
      $ sudo mv installdir/config/monit/conf.d/apache.conf installdir/config/monit/apache.conf.disabled
  • Restart the NGINX service to apply the new configuration:

      $ sudo installdir/ restart nginx

With this, your Ruby on Rails application will run at the root of your domain through the default HTTP port (80). You should now be able to access your Ruby on Rails applications with NGINX and Passenger on http://localhost/.

Last modification September 9, 2018