Question

Nginx & Unicorn multiple sinatra apps not working

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

Show comments

Submit an answer

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!

Sign In or Sign Up to Answer

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.

Want to learn more? Join the DigitalOcean Community!

Join our DigitalOcean community of over a million developers for free! Get help and share knowledge in Q&A, subscribe to topics of interest, and get courses and tools that will help you grow as a developer and scale your project or business.

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