Report this

What is the reason for this report?

Nginx & Unicorn multiple sinatra apps not working

Posted on July 27, 2015

Hello, I followed the response to this question: https://www.digitalocean.com/community/questions/nginx-and-unicorn-multiple-rails-apps

But, all requests to b.com go directly to a.com ! I’ve confirmed a different socket is running for each app.
Another thing to note, if I reverse the order of server blocks, then all a.com requests go to b.com.

This is the nginx.conf file. I’m on Ubuntu 12.04. The apps are both SInatra apps.

Where have I gone wrong?

upstream a { server unix:/var/www/html/a.com/tmp/sockets/unicorn_a.sock fail_timeout=0; }

upstream b{ server unix:/var/www/html/b.com/tmp/sockets/unicorn_b.sock fail_timeout=0; }

server { listen 80;

server_name a.com;
root /var/www/html/a.com/public;

try_files $uri @a_app;

location @a_app{
 # pass to the upstream unicorn server mentioned above 
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header Host $http_host;
    proxy_redirect off;
    proxy_pass http://a;

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

server { listen 80;

server_name b.com;
root /var/www/html/b.com/public;

try_files $uri @b_app;

location @b_app{
 # pass to the upstream unicorn server mentioned above 
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header Host $http_host;
    proxy_redirect off;
    proxy_pass http://b;

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

Thanks



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.

This question was answered by @scott.mennealy:

Actually, just found the answer here … https://www.digitalocean.com/community/questions/dns-configuration-2-domains

I needed a preceding “.”

server_name .a.com … server_name .b.com

View the original comment

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.