ruby-on-rails – 在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路由不打印“/”的任何路由,并且GET myurl.com/myapp/产生ActionController :: RoutingError(没有路由匹配[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 它找出了404 Not Found.资产也应该在子目录下,对吧?如何告诉rails在那里放/找到它们? 解决方法
为了尝试回答你的问题,我会做一些假设.
>我假设myurl.com上有一个静态网站,你只希望在myurl.com/myapp上提供Rails应用程序 根据这些假设,我相信如果你: >将您的Rails应用程序移动到?/ html / myapp文件夹下 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" >将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') > chmod x~ / html / myapp / public / dispatch.fcgi 应用程序应该开始很好,路由就好了…… 我认为您不必担心设置config.action_controller.relative_url_root. 在部署应用程序之前,我还会使用bundle install –deployment来安装你的gem. 最后,你没有获得根路由的原因是因为没有: 希望这有帮助,如果没有,请查看: Dreamhost – Rails 3 and FastCGI和FastCGI setup,其中包含一些关于使用ENV [‘RAILS_RELATIVE_URL_ROOT’]的提示 (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |