5

我正在努力解決三個主要問題,我感謝任何幫助。在Apache下的子目錄中配置Rails 4應用程序

1)如何配置Rails應用程序以myurl.com/myapp/爲根?

我試着在routes.rb

scope '/myapp' || '/' do 
    # all resources and routes go here 
    root :to => "papers#index" 

    resources :papers 
end 

environment.rb,我加入這個要頂

ENV['RAILS_RELATIVE_URL_ROOT'] = "/myapp" 

這幾乎工作,但rake routes不打印任何路線「/ 「,並且GET myurl.com/myapp/產生ActionController::RoutingError (No route matches [GET] "/")

2)它需要告訴apache什麼?

我的共享服務器的供應商建議把這個~/html/.htaccess

RewriteEngine on 
RewriteRule ^myapp/(.*)$ /fcgi-bin/rails4/$1 [QSA,L] 

/fcgi-bin/rails4

#!/bin/sh 

# This is needed to find gems installed with --user-install 
export HOME=/home/kadrian 

# Include our profile to include the right RUBY 
. $HOME/.bash_profile 

# This makes Rails/Rack think we're running under FastCGI. WTF?! 
# See ~/.gem/ruby/1.9.1/gems/rack-1.2.1/lib/rack/handler.rb 
export PHP_FCGI_CHILDREN=1 

# Get into the project directory and start the Rails server 
cd $HOME/rails4 
exec bundle exec rails server -e production 

當我點擊網站上的任何鏈接,瀏覽器的網址,例如:改變到myurl.com/fcgi-bin/rails4/papers/1,它應該是myurl.com/myapp/papers/1。我怎樣才能防止呢?

3)如何獲得資產工作

我喜歡這種感覺也會莫名其妙地被加上1解決)和2)。然而,現在,該應用程序試圖執行:

GET myurl.com/assets/application-5e86fb668d97d38d6994ac8e9c45d45e.css 

這procudes一個404 Not Found。資產也應該在subdirectoy下,對不對?我如何告訴軌道在那裏放置/找到它們?

回答

3

爲了嘗試回答你的問題,我會做出一些假設。

  1. 我假設有一個靜態的網站在myurl.com供應,您只需要Rails應用程序對myurl.com/myapp

  2. 送達我假設你的共享託管服務提供商更喜歡的FastCGI的一種方式服務於機架的應用程序(Rails)的

基於這些假設,我相信,如果你:

  1. 將您的Rails應用程序的~/html/myapp文件夾下
  2. 添加.htaccess文件~/html/myapp/public與內容:
 

    AddHandler fastcgi-script .fcgi 

    Options +FollowSymLinks +ExecCGI 

    RewriteEngine On 

    RewriteCond %{REQUEST_FILENAME} !-f 
    RewriteRule ^(.*)$ dispatch.fcgi/$1 [QSA,L] 

    ErrorDocument 500 "Rails application failed to start properly" 

  1. 添加dispatch.fcgi文件~/html/myapp/public與內容:
 

    ENV['RAILS_ENV'] ||= 'production' 
    ENV['GEM_HOME'] = File.expand_path('your_gem_home') 

    require 'fcgi' 
    require File.join(File.dirname(__FILE__), '../config/environment.rb') 

  1. chmod +x ~/html/myapp/public/dispatch.fcgi

應用程序應該開始只是罰款和路線就好了......

我不認爲你需要擔心設置config.action_controller.relative_url_root

我還會在部署您的應用程序之前使用bundle install --deployment安裝您的寶石。

最後,你沒有得到一個根本途徑,是因爲沒有: root :to => 'controller#action'config/routes.rb

希望這有助於。如果沒有,請上網:

Dreamhost - Rails 3 and FastCGIFastCGI setup,其中包括關於使用的一些提示ENV['RAILS_RELATIVE_URL_ROOT']

相關問題