2013-03-11 60 views
0

我正在使用VPS。我用rails new rails_app -d mysql創建了一個新的rails應用程序。 我正在用乘客運行nginx。我正在運行Rails 3.2.12和Ruby 1.9.3。在我的nginx.conf文件中添加以下到server指令:使用nginx移動Rails應用程序到產品

listen  80; 
server_name www.mydomain.com; 
passenger_enabled on; 
root /home/mike/www/rails_app/public; 
rails_env production; 

當我指向www.mydomain.com我看到歡迎你乘坐你on Rails的Ruby的騎!當我點擊關於應用程序的環境中我得到這個錯誤:

The page you were looking for doesn't exist. 

當我檢查我的production.log我看到這個錯誤,不知道怎麼用它做:

ActionController::RoutingError (No route matches [GET] "/rails/info/properties") 

我已經整夜通讀了,並且已經閱讀了與此類似的所有SO問題,但仍無法解決我的問題。如果我在開發中運行這一切,一切正常。

編輯

我發現這解釋爲Rails 2.3.4問題:鏈接打完一個AJAX請求到Rails /信息/屬性。屬性操作在Rails :: InfoController中定義,它位於/rails/railties/builtin/rails_info/rails/info_controller.rb中。

該路由不需要顯式定義,因爲它符合Rails的缺省路由:controller /:action /:id(儘管在這種情況下沒有ID並且控制器位於Rails名稱空間內)。

但我沒有在任何地方看到info_controller.rb

好的我發現這個:config.consider_all_requests_local是一個標誌。如果爲true,那麼任何錯誤都會導致將詳細的調試信息轉儲到HTTP響應中,並且Rails :: Info控制器將在/ rails/info/properties中顯示應用程序運行時上下文。在開發和測試環境中默認爲true,在生產模式下爲false。對於更細粒度的控制,將其設置爲false並實現local_request?在控制器中指定哪些請求應提供有關錯誤的調試信息。

但將其設置爲false什麼也不做。

編輯2 好吧,我是個白癡。發現這個地方:You're clicking the "About your application’s environment" link on the Rails default index.html page. This link only works in development environment, not in production.

而整整一個晚上,我認爲我的Rails應用程序無法正常工作。所以我想我會放棄並去睡覺。

回答

-1

我同樣面臨同樣的問題,但由於權限的限制,我發現後面的病房,我們的應用程序無法訪問特定的文件夾。

試試這個命令:

chmod -R 777 {name of your project folder}/

也許這會幫助你。

+0

不,這沒有幫助。 – mikeglaz 2013-03-11 06:18:19

0

你忘了添加passenger_base_uri:

server { 
    listen 80; 
    server_name domain.com; 
    charset utf-8; 
    root /www/domain.com/public_html; 
    passenger_enabled on; 
    passenger_base_uri /blog; 
    rails_spawn_method smart; 
    rails_env production; 
} 

此外,檢查乘客和軌道在相同的環境(生產或開發)工作。

+0

開發工作正常。我添加了passenger_base_uri,但仍然是相同的錯誤。我不明白什麼是嘗試路由到/ rails/info/properties – mikeglaz 2013-03-11 10:33:29

0

對於未來可能遇到此問題的人員,請首先檢查服務器中的生產日誌。

  1. SSH連接到你的服務器,ssh [email protected]
  2. 檢查過去的20個左右的錯誤消息tail -20 /home/username/appname/current/log/production.log
  3. 如果它在你的代碼中的錯誤(我是返回一個空數組由於空分貝),那麼修復該錯誤並再次運行cap production deploy
  4. 重複以檢查更多錯誤。