Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ruby-on-rails-3/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 3 使用Rails 3、Unicorn和;Nginx,如何访问子域的主机_Ruby On Rails 3_Nginx_Unicorn - Fatal编程技术网

Ruby on rails 3 使用Rails 3、Unicorn和;Nginx,如何访问子域的主机

Ruby on rails 3 使用Rails 3、Unicorn和;Nginx,如何访问子域的主机,ruby-on-rails-3,nginx,unicorn,Ruby On Rails 3,Nginx,Unicorn,My rails应用程序根据子域切换功能,例如blah1.mysite.com和blah2.mysite.com 我想使用request.host访问rails控制器中的子域,但对于我在浏览器中尝试的每个子域,主机总是mysite_qa。我该如何解决这个问题 我认为这是我的nginx配置的问题,我是nginx noob,因此任何帮助都将不胜感激 以下是nginx中可用的站点记录: upstream mysite_qa { ip_hash; # I

My rails应用程序根据子域切换功能,例如blah1.mysite.com和blah2.mysite.com

我想使用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

nginx可以设置包含原始主机名的头,然后应用程序可以读取该头:

    location / {
            proxy_pass http://mysite_qa;
            proxy_set_header Host $http_host;
            allow all;
    }