By Navjeet
I am trying to use the instructions at http://jrochelly.com/post/2013/08/nginx-unicorn-multiple-rails-apps/ to setup the sub uri (www.mydomain.com/site1 www.mydomain.com/site2) based Rails applications using Nginx and Unicorn.
I started with Droplet that had Unicorn and Nginx pre-installed from DO and it works fine. Now I want to setup multiple sites/Rails apps based on Sub uri.
As per the instructions I have updated nginx.conf by adding follwoing to current nginx.conf
upstream unicorn_socket_for_site2 {
server unix:/home/navjeetc/site2/current/tmp/sockets/unicorn.sock fail_timeout=0;
}
Then I created a file site2 under sites-enabled as below:
server {
location /site2/ {
try_files $uri @unicorn_proxy;
}
location @unicorn_proxy {
proxy_pass http://unix:/home/navjeetc/site2/current/tmp/sockets/unicorn.sock;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_redirect off;
proxy_set_header X-Forwarded-Proto $scheme;
}
}
And then made changes to my site2 Rails app as suggested. I did not change unicorn conf file.
But the request to http:/subdomain.mydomain.com/site2 is still going to the old Rails app and I get a 404.
The nginx config file for the old Rails app is:
server {
listen 80;
root /home/rails/current/public;
server_name _;
index index.htm index.html;
location / {
try_files $uri/index.html $uri.html $uri @app;
}
location ~* ^.+\.(jpg|jpeg|gif|png|ico|zip|tgz|gz|rar|bz2|doc|xls|exe|pdf|ppt|txt|tar|mid|midi|wav|bmp|rtf|mp3|flv|mpeg|avi)$ {
try_files $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_server;
}
}
How can I fix this?
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’d need to create a separate Unicorn configuration for each app. The Nginx setup that you’ve shared above expects Unicorn to server the Rails app locally on a Unix socket found at /home/navjeetc/site2/current/tmp/sockets/unicorn.sock Which is fine, but Unicorn isn’t actually running the second app.
If you look at /home/unicorn/unicorn.conf you’ll see that the first app is being served at 127.0.0.1:8080 which is then proxied by Nginx. The Unicorn process is started using an initscript located in /etc/init.d/unicorn You’d need a second Unicorn process to run the second app.
In total, there are three files which you would need to copy and adjust:
/home/unicorn/unicorn.conf
/etc/default/unicorn
/etc/init.d/unicorn
In many ways, it might be simpler to start from scratch than trying to repurpose the One-Click image which was build with only one app in mind. Check out this tutorial for more information. You should be able to simply follow it duplicating each step for the second 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.