【问题标题】:capistrano deploy to multiple servers with different subdomain variablecapistrano 部署到具有不同子域变量的多个服务器
【发布时间】:2012-05-30 14:31:50
【问题描述】:

I used this railscast as a basis

# nginx_unicorn.erb
upstream unicorn-<%= application %> {
  server unix:/tmp/unicorn.<%= application %>.sock fail_timeout=0;
}

server {
  listen <%= subdomain ? subdomain : application %>.example.com:443 ssl;
  server_name <%= subdomain ? subdomain : application %>.example.com;
  root <%= current_path %>/public;
  ssl                  on;
  ssl_certificate      /opt/nginx/ssl/example.com.pem;
  ssl_certificate_key  /opt/nginx/ssl/example.com.key;
  ssl_protocols SSLv3 TLSv1;
  ssl_ciphers ALL:-ADH:+HIGH:+MEDIUM:-LOW:-SSLv2:-EXP;
  ssl_session_cache shared:SSL:10m;
  try_files $uri/index.html $uri @unicorn;

  location ^~ /assets/ {
    gzip_static on;
    expires max;
    add_header Cache-Control public;
  }
  location @unicorn {
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header Host $http_host;
    proxy_set_header X-Forwarded-Proto https;
    proxy_redirect off;
    proxy_pass http://unicorn-<%= application %>;
  }

  error_page 500 502 503 504 /500.html;
  client_max_body_size 4G;
  keepalive_timeout 10;
}

我在 deploy.rb 中为子域设置了一个变量

# deploy.rb
...
role :web, "avps.example.com", "bvps.example.com", "cvps.example.com"
role :app, "avps.example.com", "bvps.example.com", "cvps.example.com"
role :db, "avps.example.com", "bvps.example.com", "cvps.example.com", :primary => true
set :subdomain, "atsp"
...

当我只部署到一台服务器时,这很有效,但我希望能够基于它正在部署到的当前服务器,所以如果它是 avps.example.com,它会:

set :subdomain, "atsp"

或者如果它是 bvps.example.com,它会这样做:

set :subdomain, "btsp"

有没有简单的方法可以做到这一点?

【问题讨论】:

  • 感谢单台服务器的帮助:)

标签: deployment nginx capistrano


【解决方案1】:

我认为您正在寻找的是 Capistrano 多阶段部署。你可以找到维基页面here。您所要做的就是移动

set :subdomain, "atsp"

到包含服务器信息的文件(即 config/deploy/atsp.rb)中,然后您可以部署到该服务器

cap atsp deploy

希望这会有所帮助。

【讨论】:

    猜你喜欢
    • 2012-06-22
    • 2012-07-20
    • 1970-01-01
    • 2014-05-26
    • 1970-01-01
    • 2021-06-07
    • 2011-10-09
    • 1970-01-01
    • 2011-08-26
    相关资源
    最近更新 更多