2012-05-30 47 views
1

I used this railscast as a basisCapistrano的部署到多個服務器使用不同的子域變量

# 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" 

是否有一個簡單的方法來做到這一點?

+0

感謝您對單個服務器的幫助:) –

回答

0

我想你正在尋找的是Capistrano多階段部署。你可以找到維基頁面here。所有你必須做的是移動

set :subdomain, "atsp" 

到一個文件(即配置/部署/ atsp.rb)與服務器信息,然後就可以部署到服務器

cap atsp deploy 

希望這可以幫助。

相關問題