Nginx & Unicorn multiple sinatra apps not working

July 27, 2015 1.4k views
DNS Nginx Sinatra Ubuntu

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/unicorna.sock failtimeout=0;
}

upstream b{
server unix:/var/www/html/b.com/tmp/sockets/unicornb.sock failtimeout=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;

}
errorpage 500 502 503 504 /500.html;
client
maxbodysize 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;

}
errorpage 500 502 503 504 /500.html;
client
maxbodysize 4G;
keepalive_timeout 10;
}

Thanks

1 comment
1 Answer

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 "."

servername .a.com
.....
server
name .b.com

View the original comment

Have another answer? Share your knowledge.