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!
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:
Create your new Rails app in a new directory:
- cd ~
- rails new my_second_app
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.
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.
Create a symbolic link to the new Nginx configuration file in the sites-enabled directory:
- sudo ln -s /etc/nginx/sites-available/my_second_app /etc/nginx/sites-enabled/
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:
- sudo service unicorn_my_second_app restart
- 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.
Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.
Full documentation for every DigitalOcean product.
The Wave has everything you need to know about building a business, from raising funding to marketing your product.
Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.
New accounts only. By submitting your email you agree to our Privacy Policy
Scale up as you grow — whether you're running one virtual machine or ten thousand.
Sign up and get $200 in credit for your first 60 days with DigitalOcean.*
*This promotional offer applies to new accounts only.