Report this

What is the reason for this report?

Nginx and Unicorn Multiple Rails apps

Posted on June 14, 2014

Hello,

I followed this guide and everything went smooth!

https://www.digitalocean.com/community/tutorials/how-to-deploy-rails-apps-using-unicorn-and-nginx-on-centos-6-5

I got a rails app up and running with no problems. But I have spent a lot of time tiring to get multiple apps running with no success.

I have tried to edit the TheApp/config/unicorn.rb for each app and /etc/nginx/conf.d/default.conf.

Are there any examples of how these files should be setup for multiple apps?

Also: When I run unicorn_rails -c config/unicorn.rb -D for the 2nd app i get the following error:

/usr/local/rvm/gems/ruby-2.1.0/gems/unicorn-4.8.3/lib/unicorn/configurator.rb:75:in `read’: No such file or directory @ rb_sysopen - config/unicorn.rb (Errno::ENOENT)

Can anyone help please?



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.

Have your tried VirtualHosts? With properly setup you can have different domains/folder.

For each app, you need to make sure unicorn is listening on a different socket. In the app’s <code>config/unicorn.rb</code>, change the socket value to be unique: <pre> listen “/tmp/unicorn.app_one.sock” </pre> Then in the Nginx configuration, you’ll need a new server block for each app. It will look something like: <pre> upstream app_one { # Path to Unicorn SOCK file, as defined previously server unix:/tmp/unicorn.app_one.sock fail_timeout=0; }

upstream app_two { server unix:/tmp/unicorn.app_two.sock fail_timeout=0; }

server { listen 80; server_name domain-for-app_one.com;

# Application root, as defined previously
root /root/app_one/public;

try_files $uri/index.html $uri @app;

location @app {
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header Host $http_host;
    proxy_redirect off;
    proxy_pass http://app_one;
}

error_page 500 502 503 504 /500.html;
client_max_body_size 4G;
keepalive_timeout 10;

}

server { listen 80; server_name domain-for-app_two.com;

# Application root, as defined previously
root /root/app_two/public;

try_files $uri/index.html $uri @app;

location @app {
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header Host $http_host;
    proxy_redirect off;
    proxy_pass http://app_two;
}

error_page 500 502 503 504 /500.html;
client_max_body_size 4G;
keepalive_timeout 10;

}
</pre>

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.