2013-05-07 47 views
0

我的Rails應用根據子域切換功能,例如, blah1.mysite.com & blah2.mysite.com使用Rails 3,Unicorn&Nginx,我如何訪問子域的主機

我想通過使用request.host訪問我的rails控制器中的子域,但對於我在瀏覽器中嘗試的每個子域,主機總是mysite_qa。我該如何解決?

我認爲這是我的nginx配置的問題,我是一個nginx noob,所以任何幫助,將不勝感激。

這裏是nginx的站點可用的記錄:

upstream mysite_qa { 
     ip_hash;     # If you enable the second one and don't make sessions common 
     server localhost:9002; 
} 

server { 
     client_max_body_size 20M; 
     listen 80; 
     #listen 443 ssl;   # If you end up enabling SSL 
     server_name qa.mysite.com; 
     server_name blah1.mysite.com; 
     server_name blah2.mysite.com; 
     location/{ 
       proxy_pass http://mysite_qa; 
       allow all; 
     } 
     location /nginx_status { 
       stub_status on; 
       access_log off; 
       allow 10.8.0.0/24; 
       allow 172.16.0.0/16; 
       deny all; 
     } 

} 

這裏是我的麒麟文件:

worker_processes 4 

APP_PATH = "/var/www/qa.mysite.com" 
working_directory APP_PATH 

stderr_path APP_PATH + "/log/unicorn.stderr.log" 
stdout_path APP_PATH + "/log/unicorn.stderr.log" 

pid APP_PATH + "/tmp/pid/unicorn.pid" 

listen 9002, :tcp_nopush => true 

# nuke workers after 30 seconds instead of 60 seconds (the default) 
timeout 30 

preload_app true 
GC.respond_to?(:copy_on_write_friendly=) and 
    GC.copy_on_write_friendly = true 

before_fork do |server, worker| 
    # the following is highly recomended for Rails + "preload_app true" 
    # as there's no need for the master process to hold a connection 
    defined?(ActiveRecord::Base) and 
    ActiveRecord::Base.connection.disconnect! 
end 

after_fork do |server, worker| 
    defined?(ActiveRecord::Base) and 
    ActiveRecord::Base.establish_connection 
end 

我運行Ubuntu 12.04.1

nginx的版本:nginx的/1.1.19

回答

相關問題