Report this

What is the reason for this report?

How to run rails applications on digitalocean using "rails s"

Posted on August 30, 2018
Jsom

By Jsom

Hello everyone,

My issue is that I created a droplet to develop Rails apps. I used the one-click ruby droplet. And now I want to create more than the default rails apps in this droplet.

The issue here is that it comes installed with nginx/unicorn … And they’re always on with path of default rails project in their config files.

Now let’s assume I created another rails app(file) and I want to run it using “rails s” instead of default rails app that is created by the droplet. How can I do it?

Note: I don’t want to change the file path in configs each time I decide to try another app

PS: I tried stopping the service of unicorn/nginx one at a time and both of them in the same time to use “rail s” to run the app … But it didn’t work … Web pages were not loading

I know it might be a question of a rookie. But I’m kinda new to these stuff and I’d appreciate it if anyone could help me.



This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

You can indeed run multiple Rails applications on a single server. However, you will need to configure Nginx and Unicorn (or Passenger, Puma, etc.) for each Rails application you want to serve.

It is not recommended to switch apps by manually starting/stopping services or running “rails s” for production. This command starts a server intended for development, which is not suitable for handling real-world traffic.

Here’s a simplified process to set up a new Rails app alongside your existing one:

  1. Create a new Rails app:

Create your new Rails app in a new directory:

  1. cd ~
  2. rails new my_second_app
  1. Set up a new Unicorn configuration:

You should create a separate Unicorn configuration file for your new app. The file might be located at ~/my_second_app/config/unicorn.rb, and it should be different from your existing Unicorn configuration to avoid conflicts.

  1. Set up a new Nginx server block:

Create a new Nginx configuration file for your new app. This will likely be a new file in the /etc/nginx/sites-available/ directory. The server block should have a different server_name from your existing configuration, and it should proxy requests to the Unicorn socket for your new app.

  1. Link the Nginx server block:

Create a symbolic link to the new Nginx configuration file in the sites-enabled directory:

  1. sudo ln -s /etc/nginx/sites-available/my_second_app /etc/nginx/sites-enabled/
  1. Restart Unicorn and Nginx:

Finally, you need to restart Unicorn and Nginx for your changes to take effect. How you do this depends on how you have set up your server. It might look something like this:

  1. sudo service unicorn_my_second_app restart
  2. sudo service nginx restart

This setup allows you to run both apps simultaneously, each with its own domain name. Note that if you are using the same droplet, you will need to point a new domain name to your droplet’s IP address for the new Rails application. This new domain should match the server_name in your Nginx server block for the new app.

The developer cloud

Scale up as you grow — whether you're running one virtual machine or ten thousand.

Get started for free

Sign up and get $200 in credit for your first 60 days with DigitalOcean.*

*This promotional offer applies to new accounts only.