问题
I've set up my server for this tutorial (https://coderwall.com/p/ttrhow/deploying-rails-app-using-nginx-puma-and-capistrano-3)
When I used one project, all works, but when I added another project to this VPS, I have error
[emerg] 20737#0: duplicate upstream "puma" in /etc/nginx/sites-enabled/vsejalreg:1
My nginx's configure
upstream puma {
server unix:///home/deployer/apps/vsejalreg/shared/tmp/sockets/vsejalreg-puma.sock;
}
server {
listen 80;
server_name wjreg.rubyserv.ru www.wjreg.rubyserv.ru;
root /home/deployer/apps/vsejalreg/current/public;
access_log /home/deployer/apps/vsejalreg/current/log/nginx.access.log;
error_log /home/deployer/apps/vsejalreg/current/log/nginx.error.log info;
location ^~ /assets/ {
gzip_static on;
expires max;
add_header Cache-Control public;
}
try_files $uri/index.html $uri @puma;
location @puma {
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_redirect off;
proxy_pass http://puma;
}
error_page 500 502 503 504 /500.html;
client_max_body_size 10M;
keepalive_timeout 10;
}
And
upstream puma {
server unix:///home/deployer/apps/register/shared/tmp/sockets/register-puma.sock;
}
server {
listen 80;
server_name ws.rubyserv.ru www.ws.rubyserv.ru;
root /home/deployer/apps/register/current/public;
access_log /home/deployer/apps/register/current/log/nginx.access.log;
error_log /home/deployer/apps/register/current/log/nginx.error.log info;
location ^~ /assets/ {
gzip_static on;
expires max;
add_header Cache-Control public;
}
try_files $uri/index.html $uri @puma;
location @puma {
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_redirect off;
proxy_pass http://puma;
}
error_page 500 502 503 504 /500.html;
client_max_body_size 10M;
keepalive_timeout 10;
}
When I add nginx configure one by one - all work!
How fix this bag or puma not working with many project?
Thx!
回答1:
Puma works with any proper configured project :) You can configure named upstream (upstream puma) just once, not with every server configuration. If you need different puma instances for each server, just setup upstreams with different names.
upstream puma_vsejalreg {
server unix://...PATH.../vsejalreg-puma.sock;
}
upstream puma_register {
server unix://...PATH.../register-puma.sock;
}
回答2:
Please note, that you need to change this part aswell:
location @puma {
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_redirect off;
proxy_pass http://puma;
}
Else you will run into errors such as this - nginx: [emerg] host not found in upstream "puma" in /etc/nginx/sites-enabled/furnitureapp:25
So, if you rename your upstream to
upstream puma_register
You need to rename your proxy_pass as well to
location @puma {
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_redirect off;
proxy_pass http://puma_register; <------ Change here
}
来源:https://stackoverflow.com/questions/29169098/rails-nginx-puma-duplicate-upstream-puma-in-etc-nginx-sites-enabled