【问题标题】:rails app showing files instead of showing the apprails 应用程序显示文件而不是显示应用程序
【发布时间】:2014-07-10 01:36:03
【问题描述】:

我使用的是 bluehost 共享服务器

它应该是一个显示在根域 domainname.com 中

rails 文件位于:

public_html/app_name/current

我的 public_html/.htaccess 有:

RewriteEngine on
RewriteCond %{HTTP_HOST} ^(www.)?domainname.com$
RewriteCond %{REQUEST_URI} !^/app_name/current/public/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /app_name/current/public/$1
RewriteCond %{HTTP_HOST} ^(www.)?domainname.com$
RewriteRule ^(/)?$ /app_name/current/public/ [L]

我的 public_html/app_name/current/public/.htaccess 有:

Allow from all
Options -MultiViews
PassengerResolveSymlinksInDocumentRoot on
RailsEnv production
RackBaseURI /public_html/app_name/current       
SetEnv GEM_HOME /home1/username/ruby/gems

【问题讨论】:

    标签: ruby-on-rails ruby apache .htaccess deployment


    【解决方案1】:

    既然我自己解决了,我会发布答案,这可能对某人有所帮助 当我添加到我的 public_html/app_name/current/public/.htaccess 时,事情开始变得清晰

    PassengerAppRoot /home1/user/public_html/app_name/current
    

    然后我开始看到一个空白页并开始显示在 rails 日志中:

    ActionController::RoutingError (No route matches [GET] "/app_name/current/public"):
    

    然后我意识到,好的 Rails 正在运行,现在这是一个路由问题,但是为什么它在日志中显示“/app_name/current/public”,因为我没有尝试访问此路由? 好吧,它与我的 public_html/.htaccess 中的路径相同,然后我发现我有所有系统变量来引用我的 public_html/app_name/current/public/.htaccess 中的 Rails 路径我必须摆脱public_html/.htaccess 配置。

    所以,我删除了 public_html/app_name/current/public/.htaccess 文件并将所有内容添加到 public_html/.htaccess 中:

    RewriteEngine on
    RewriteCond %{HTTP_HOST} ^(www.)?domainname.com$
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{HTTP_HOST} ^(www.)?domainname.com$  
    
    Allow from all
    Options -MultiViews
    PassengerResolveSymlinksInDocumentRoot on
    RailsEnv production
    RackBaseURI /public_html/app_name/current
    SetEnv GEM_HOME /home1/user/ruby/gems
    PassengerAppRoot /home1/user/public_html/app_name/current
    

    然后我遇到了一个问题,我的公共/上传下的图像没有显示,所以我添加了:

    RewriteRule ^uploads/(.*)$  /faux/current/public/uploads/$1 [R=301,NC,L]
    

    【讨论】:

    • 很好 - 喜欢人们分享他们的解决方案 :) 所以你在使用 Apache 和Passenger?
    • 你好 Rich,是的,Apache with Passenger :)
    猜你喜欢
    • 1970-01-01
    • 2015-07-11
    • 1970-01-01
    • 1970-01-01
    • 2015-04-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多