【问题标题】:setting up a virtual host with unicorn, nginx and capistrano in rails在 rails 中使用 unicorn、nginx 和 capistrano 设置虚拟主机
【发布时间】:2012-11-08 07:40:49
【问题描述】:

我已经能够使用 nginx、unicorn 和 capistrano 将我的 rias 应用程序部署到 vps 系统中,没有任何错误。现在,我想在同一个 vps 服务器中使用相同的 nginx 配置(下面的两个脚本)部署另一个 rails 应用程序,并在运行 cap deploy:setup 和 cap deploy:cold 后正确设置并将 rails 应用程序发送到服务器。我得到的问题是这个。当我输入service nginx restart 时出现以下错误

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

我当前正在运行的第一个应用程序的 nginx 脚本是

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;
}

我的第二个 rails 应用程序的 nginx 配置无法运行,而是为第一个 rails 应用程序引发错误并使其崩溃是

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;
}

任何想法如何解决此问题并正确设置虚拟主机。谢谢你

【问题讨论】:

    标签: ruby-on-rails ruby-on-rails-3 nginx ruby-on-rails-3.2 capistrano


    【解决方案1】:

    以不同的方式命名您的第二个上游应用(上游名称必须是唯一的)。因此,不要使用unicorn,而是使用名称@my_shiny_app_server。然后使用这个名字proxy_pass指令http://my_shiny_app_server。将 my_shiny 字符串替换为您的应用名称,例如gutrees, cf.

    【讨论】:

    • 不错。这修复了第一个错误。新的错误是nginx: configuration file /etc/nginx/nginx.conf test failed。我还将第二个应用程序的@unicorn 变量更新为@gutrees。我应该这样做吗?
    • 第二个错误在部署到服务器后仍然出现,当我输入第一个正在运行的应用程序的 url 时,它会崩溃
    猜你喜欢
    • 2015-05-03
    • 1970-01-01
    • 1970-01-01
    • 2016-01-03
    • 2017-01-07
    • 2023-03-15
    • 2011-01-11
    • 2014-11-12
    • 2012-05-07
    相关资源
    最近更新 更多