I have been able to deploy my rials app into a vps system using nginx, unicorn and capistrano with no errors. Now, i want to deploy another rails app using the same nginx config(the two scripts are below) inside the same vps server and after running cap deploy:setup and cap deploy:cold it sets up correctly and the rails app is sent to the server. The problem i get is this. 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 app which is currently running is
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 app which fails to run but instead trows an error for the first rails app and makes it to crash is
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 issue and set up the virtual host correctly. Thank you
Name your second apps upstream differently (upstream names need to be unique). So instead of unicorn
use i.e. the name @my_shiny_app_server
. Then use this name proxy_pass directive http://my_shiny_app_server
. Replace the my_shiny
string with the name of your app e.g. gutrees
, cf
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With