# 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"
有没有简单的方法来实现这一点?