One domain name for multiple Rails applications with Nginx and Unicorn

I have two Rails applications, and I want to host them with only one domain name:

app1.example.com app2.example.com 

I have VPS on the digital ocean, and I have already run one application with Nginx and Unicorn. This is my nginx config file:

 upstream app1{ server unix:/tmp/unicorn.app1.sock fail_timeout=0; } #upstream app2{ # server unix:/tmp/unicorn.app2.sock fail_timeout=0; #} server{ listen 80; root /var/www/app1/public; try_files $uri/index.html $uri.html $uri @app; location @app{ proxy_pass http://app1; } error_page 500 502 503 504 /500.html; } 

I seem to need another server block to host another application, but I don't know how to let nginx distinguish between two server blocks, since I only have one domain. Any ideas?

+5
source share
1 answer

ok, since you have already defined 2 subdomains, you just need to add server_name to nginx blocks

 upstream app1{ server unix:/tmp/unicorn.app1.sock fail_timeout=0; } upstream app2{ server unix:/tmp/unicorn.app2.sock fail_timeout=0; } server{ listen 80; server_name app1.domain.com; root /var/www/app1/public; try_files $uri/index.html $uri.html $uri @app; location @app{ proxy_pass http://app1; } error_page 500 502 503 504 /500.html; } server{ listen 80; server_name app2.domain.com; root /var/www/app2/public; try_files $uri/index.html $uri.html $uri @app; location @app{ proxy_pass http://app2; } error_page 500 502 503 504 /500.html; } 
+5
source

Source: https://habr.com/ru/post/1202556/


All Articles