Creating a virtual host with unicorn, nginx and capistrano in rails

I was able to deploy the rials application on a vps system using nginx, unicorn and capistrano without errors. Now I want to deploy another rails application using the same nginx configuration (two scenarios below) inside the same vps server and after deploying the cover: installing and deploying the cover: it installs coldly and the rails application is sent to the server. The problem is that I understand. when i type service nginx restart i get the following error

 nginx: [emerg] duplicate upstream "unicorn" in /etc/nginx/sites-enabled/cf:1 nginx: configuration file /etc/nginx/nginx.conf test failed 

my nginx script for the first application that is currently running,

 upstream unicorn { server unix:/tmp/unicorn.cf.sock fail_timeout=0; } server { listen 80 default deferred; server_name cfmagazineonline.com; root /home/deployer/apps/cf/current/public; location ^~ /assets/ { gzip_static on; expires max; add_header Cache-Control public; } try_files $uri/index.html $uri @unicorn; location @unicorn { proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header Host $http_host; proxy_redirect off; proxy_pass http://unicorn; } error_page 500 502 503 504 /500.html; client_max_body_size 4G; keepalive_timeout 10; } 

my nginx config for the second rails application that does not start, but instead fails for the first rails application and crashes

 upstream unicorn { server unix:/tmp/unicorn.gutrees.sock fail_timeout=0; } server { listen 80 default deferred; server_name gutrees.com; root /home/deployer/apps/gutrees/current/public; location ^~ /assets/ { gzip_static on; expires max; add_header Cache-Control public; } try_files $uri/index.html $uri @unicorn; location @unicorn { proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header Host $http_host; proxy_redirect off; proxy_pass http://unicorn; } error_page 500 502 503 504 /500.html; client_max_body_size 4G; keepalive_timeout 10; } 

Any ideas how I can fix this problem and configure the virtual host correctly. thank you

+4
source share
1 answer

Name your minor applications upstream (upstream names must be unique). So instead of unicorn use the name @my_shiny_app_server . Then use this name proxy_pass directive http://my_shiny_app_server . Replace the string my_shiny name of your application, for example. gutrees , cf

+10
source

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


All Articles