2012-04-27 53 views
1

所以這在我的開發模式下工作,但是當我嘗試使用乘客部署我的導軌應用程序時,我的控制器似乎沒有被調用。如何讓我的導軌控制器通過Passenger與子域一起使用?

我已經爲www.example.com設置了API的cname記錄。另外,我使用的是Rails 3.2和Ruby 1.9.3。

以下是我的routes.rb文件的相關部分。

# API 
constraints :subdomain => 'api' do 
    scope :module => 'api' do #:constraints => { :format => :json } do 
    match '*skippydoo' => redirect('/'), :format => :html 
    root :to => 'pages#developer', :format => :html 
    end 
end 

這裏的Apache配置:

# PassengerHighPerformance on 
PassengerMaxPoolSize 12 
PassengerPoolIdleTime 1500 
# PassengerMaxRequests 1000 
PassengerStatThrottleRate 120 
# RackAutoDetect Off 
# RailsAutoDetect Off 

NameVirtualHost 10.28.124.130:80 

<VirtualHost 10.28.124.130:80> 

ServerName application.example.com 
ServerAlias application 

DocumentRoot /var/www/application/current/public/ 
<Directory /var/www/application/current/public> 
     Options +FollowSymLinks 
     AllowOverride All 
     Order allow,deny 
     allow from all 
</Directory> 
RackBaseURI/
RackEnv staging 

ErrorDocument 503 /system/maintenance.html 
RewriteEngine On 
RewriteLog /var/www/application/current/log/rewrite_log 
RewriteLogLevel 9 
RewriteCond %{REQUEST_URI} !.(css|gif|jpg|png)$ 
RewriteCond %{DOCUMENT_ROOT}/system/maintenance.html -f 
RewriteCond %{SCRIPT_FILENAME} !maintenance.html 
RewriteRule ^.*$ - [redirect=503,last] 

</VirtualHost> 

<VirtualHost 10.28.124.130:80> 

ServerName api.application.example.com 
ServerAlias api.application 

DocumentRoot /var/www/application-api/current/public 
<Directory /var/www/application-api/current/public> 
     Options +FollowSymLinks 
     AllowOverride All 
     Order allow,deny 
     allow from all 
</Directory> 
RackBaseURI/
RackEnv staging 
</VirtualHost> 

這只是使一些文檔,我寫我的描述API。

我可以將文檔根切換到某個空目錄並獲取該渲染,所以我知道Apache工作正常。 application-api目錄是我部署的應用程序的符號鏈接。

我的API控制器生命$RAILS_ROOT/app/controllers/api/pages_controller.rb,但實際上做的工作之一是$RAILS_ROOT/app/controllers/pages_controller.rb

Started GET "/" for 10.29.28.157 at 2012-04-26 21:12:51 -0500 
Processing by PagesController#home as HTML 
    Rendered pages/home.html.erb within layouts/application (283.7ms) 
    Rendered layouts/_stylesheets.html.erb (4.4ms) 
    Rendered layouts/_header.html.erb (5.7ms) 
    Rendered layouts/_footer.html.erb (0.4ms) 
Completed 200 OK in 522ms (Views: 394.4ms | ActiveRecord: 12.1ms | Solr: 0.0ms) 

那麼,是什麼原因呢?爲什麼它在開發中工作,而不是生產?

回答

1

我沒有看到您的www子域的VirtualHost。 Apache甚至將請求發送給Passenger?

也許你需要改變你的ServerName,或者添加另一個ServerAlias?

+0

虛擬主機是那裏的第二個VirtualHost塊,用於api子域;沒有'www'子域 – gaahrdner 2012-04-27 04:57:55

+0

我明白了。我對你的「www.example.com」參考感到困惑。這是一個刺,將:subdomain約束更改爲「api.application」。如果你看看ActionDispatch :: Http :: URL.subdomain,你會發現它會返回兩者。 – 2012-04-27 14:34:45

+0

唉,那沒用。但是,你確實讓我走上了正確的道路! – gaahrdner 2012-05-10 06:15:15

1

於是,我改變了我的限制是:

constraints :subdomain => /^api/ do 

並開始工作。現在,爲什麼正則表達式會起作用,並專門命名子域名對我來說不是一個驚喜!

相關問題