配置的Rails应用4用于生产的Apache下的子目录 [英] Configuring a Rails 4 app for production in a subdirectory under Apache
问题描述
有我有,我AP preciate挣扎任何人有任何帮助三大问题。
1)如何配置Rails应用程序有 myurl.com/myapp /
作为根?
我试过的routes.rb
:
范围'/ MyApp的'|| '/'做
#所有资源和路线去这里
根:以= GT; 的论文#指数 资源:论文
结束
和的environment.rb
,我说这个要顶
ENV ['RAILS_RELATIVE_URL_ROOT'] =/ MyApp的
这几乎工程,但耙路线
不打印任何途径为/和 GET myurl.com/myapp/
产生的ActionController :: RoutingError(无路由匹配[GET]/)
2)什么是需要告诉Apache?
我的共享服务器的供应商建议把这个〜/ HTML /的.htaccess
RewriteEngine叙述上
重写规则^的myapp /(.*)$ / FCGI斌/ rails4 / $ 1 [QSA,L]
与 / FCGI斌/ rails4
是
#!/ bin / sh的#这是需要找到安装宝石--user安装
出口HOME = /家庭/ kadrian#包括我们的个人资料,包括正确的RUBY
。 $ HOME / .bash_profile中#这使导轨/机架认为我们的FastCGI下运行。 WTF?
#看看〜/ .gem /红宝石/ 1.9.1 /宝石/机架1.2.1 / lib中/架/ handler.rb
出口PHP_FCGI_CHILDREN = 1#获取到项目目录并启动Rails服务器
CD $ HOME / rails4
EXEC捆绑EXEC轨服务器-e生产
当我点击网站上的任何链接,浏览器的网址,例如改变到 myurl.com/fcgi-bin/rails4/papers/1
,它应该是 myurl.com/myapp/papers/1
。我怎样才能prevent呢?
3)如何获得资产的工作
我喜欢这种感觉也会莫名其妙地被一起解决1)和2)。然而,现在,应用程序试图做的事:
GET myurl.com/assets/application-5e86fb668d97d38d6994ac8e9c45d45e.css
这procudes一个 404未找到
。资产应该是subdirectoy下过,对吧?我如何告诉轨将/在那里找到他们?
有几个假设我会以尝试回答你的问题做出。
-
我假设有一个静态的网站在
myurl.com
供应早餐,您只需要在滑轨上的myurl.com/myapp </ code>
-
我假设你的共享主机提供商prefers的FastCGI的方式来服务于机架的应用程序(Rails)的
,我相信,如果你:
- 将您的Rails应用程序的
〜/ HTML /的myapp </ code>文件夹下
- 添加
的.htaccess
文件复制到〜/ HTML / MyApp的/公共
的内容是:
AddHandler的FastCGI的脚本.fcgi 选项+ +了FollowSymLinks ExecCGI RewriteEngine叙述在 的RewriteCond%{} REQUEST_FILENAME!-f
重写规则^(。*)$ dispatch.fcgi / $ 1 [QSA,L] 500的ErrorDocumentRails应用程序未能正确启动
- 添加
dispatch.fcgi
文件复制到〜/ HTML / MyApp的/公共
的内容是:
ENV ['RAILS_ENV'] || =生产
ENV ['GEM_HOME'] = File.expand_path('your_gem_home') 需要'FCGI
需要File.join(File.dirname(__ FILE__),../config/environment.rb')
-
使用chmod + x〜/ HTML / MyApp的/公/ dispatch.fcgi
应用程序应该开始只是罚款和路由就好了......
我不认为你需要担心设置 config.action_controller.relative_url_root
。
我也使用安装宝石捆绑安装--deployment
之前部署的应用程序。
最后,你没有得到一个根路径的原因是因为没有:根:给= GT;在控制器#行动
你的的config / routes.rb中
希望这有助于如果没有,请查看:
Dreamhost的 - 轨道3和FastCGI 和的 FastCGI的设置其中包括有关使用一些提示 ENV ['RAILS_RELATIVE_URL_ROOT']
There are three major issues I'm struggling with, I appreciate any help for any of them.
1) How do I configure the Rails app to have myurl.com/myapp/
as the root?
I tried in routes.rb
:
scope '/myapp' || '/' do
# all resources and routes go here
root :to => "papers#index"
resources :papers
end
and in environment.rb
, i added this to the top
ENV['RAILS_RELATIVE_URL_ROOT'] = "/myapp"
This nearly works, except that rake routes
doesn't print any route for "/", and GET myurl.com/myapp/
produces ActionController::RoutingError (No route matches [GET] "/")
2) What do it need to tell apache?
The provider of my shared server suggest to put this to ~/html/.htaccess
RewriteEngine on
RewriteRule ^myapp/(.*)$ /fcgi-bin/rails4/$1 [QSA,L]
with /fcgi-bin/rails4
being
#!/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
When I click any link on the site, the browser url changes e.g. to myurl.com/fcgi-bin/rails4/papers/1
, where it should be myurl.com/myapp/papers/1
. How can I prevent that?
3) How to get the assets working
I feel like this will be solved somehow together with 1) and 2). However, right now, the app tries to do:
GET myurl.com/assets/application-5e86fb668d97d38d6994ac8e9c45d45e.css
which procudes a 404 Not Found
. The assets should be under the subdirectoy too, right? How do I tell rails to put / find them there?
There are a few assumptions I'm going to make in order to try and answer your question.
I'm assuming there is a static site served at
myurl.com
and that you only want the Rails app to be served onmyurl.com/myapp
I'm assuming your shared hosting provider prefers FastCGI as a way to serve Rack apps (Rails)
Based on those assumptions, I believe that if you:
- Move your Rails app under the
~/html/myapp
folder - Add a
.htaccess
file to~/html/myapp/public
with contents:
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"
- Add a
dispatch.fcgi
file to~/html/myapp/public
with contents:
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
the app should start just fine and route just fine...
I don't think you need to worry about setting config.action_controller.relative_url_root
.
I would also install your gems using bundle install --deployment
prior to deploying your app.
Finally, the reason you're not getting a root route is because there is no:
root :to => 'controller#action'
in your config/routes.rb
Hope this helps and if not, check out:
Dreamhost - Rails 3 and FastCGI and FastCGI setup which includes some hints about using ENV['RAILS_RELATIVE_URL_ROOT']
这篇关于配置的Rails应用4用于生产的Apache下的子目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!