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']

相关问题