【问题标题】:How to access rails app after starting up on the server在服务器上启动后如何访问rails应用程序
【发布时间】:2014-03-21 18:43:34
【问题描述】:

我是 ruby​​ on rails 的新手,我一直在使用 JustHost 来试用我的测试 rails 应用程序。但是,据我了解,JustHost 使用 Phusion Passenger 来部署 rails app。我可以让本地版本工作,它只是一个使用“rails new testapp”创建的新应用程序,但我不断收到此错误:

没有这样的文件或目录 - config.ru

我能够在服务器上运行 rails 并收到以下结果:

=> Booting WEBrick
=> Rails 4.0.3 application starting in development on http://0.0.0.0:3000
=> Run `rails server -h` for more startup options
=> Ctrl-C to shutdown server
[2014-03-21 12:35:49] INFO  WEBrick 1.3.1
[2014-03-21 12:35:49] INFO  ruby 1.9.3 (2013-05-15) [x86_64-linux]
[2014-03-21 12:35:49] INFO  WEBrick::HTTPServer#start: pid=17181 port=3000

运行 bundle exec Passenger start 给了我以下信息:

=============== Phusion Passenger Standalone web server started ===============
PID file: /home4/USER/APPNAME/tmp/pids/passenger.3000.pid
Log file: /home4/USER/APPNAME/log/passenger.3000.log
Environment: development
Accessible via: http://0.0.0.0:3000/

You can stop Phusion Passenger Standalone by pressing Ctrl-C.
Problems? Check http://www.modrails.com/documentation/Users%20guide%20Standalone.html#troubleshooting
===============================================================================
App 23867 stdout: 
[ 2014-03-21 12:36:54.9704 23567/7f2d68154700 Pool2/SmartSpawner.h:301 ]: Preloader for /home4/USER/APPNAME started on PID 23867, listening on unix:/tmp/passenger.1.0.23557/generation-0/backends/preloader.23867
App 24159 stdout: 


Started HEAD "/" for 127.0.0.1 at 2014-03-21 12:36:55 -0600
Processing by Rails::WelcomeController#index as HTML
  Rendered /home4/USER/ruby/gems/gems/railties-4.0.3/lib/rails/templates/rails/welcome/index.html.erb (4.8ms)
Completed 200 OK in 92ms (Views: 54.4ms | ActiveRecord: 0.0ms)

我按照 JustHost 上的教程进行操作,但仍然无法访问该页面。 my.justhost.com/cgi/help/rails

而且我还将公用文件夹中的 .htaccess 修改为以下内容,但未成功。更改为以下代码后,当我访问我的 rails 应用程序的公用文件夹时,我会看到文件夹中的文件列表,例如。 404.html、422.html等

<IfModule mod_passenger.c>
Options -MultiViews
PassengerResolveSymlinksInDocumentRoot on
#Set this to whatever environment you'll be running in
RailsEnv production
#Set this to work with Phusion Passenger online 
RackBaseURI /home4/USER/APPNAME
SetEnv GEM_HOME /home1/examplec/ruby/gems
</IfModule>

USER 是我的用户名,APPNAME 是我的 rails 应用程序的名称。

感谢您的所有帮助。

除了以上所有信息,我还附上了我的 Gemfile 作为参考:

source 'https://rubygems.org'

# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '4.0.3'
gem 'passenger', :require => false
# Use sqlite3 as the database for Active Record
gem 'sqlite3'

# Use SCSS for stylesheets
gem 'sass-rails', '~> 4.0.0'

# Use Uglifier as compressor for JavaScript assets
gem 'uglifier', '>= 1.3.0'

# Use CoffeeScript for .js.coffee assets and views
gem 'coffee-rails', '~> 4.0.0'

# See https://github.com/sstephenson/execjs#readme for more supported runtimes
# gem 'therubyracer', platforms: :ruby

# Use jquery as the JavaScript library
gem 'jquery-rails'

# Turbolinks makes following links in your web application faster. Read more: https://github.com/rails/turbolinks
gem 'turbolinks'

# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
gem 'jbuilder', '~> 1.2'

group :doc do
  # bundle exec rake doc:rails generates the API under doc/api.
  gem 'sdoc', require: false
end

gem 'execjs'
gem 'therubyracer', :platforms => :ruby

# Use ActiveModel has_secure_password
# gem 'bcrypt-ruby', '~> 3.1.2'

# Use unicorn as the app server
# gem 'unicorn'

# Use Capistrano for deployment
# gem 'capistrano', group: :development

# Use debugger
# gem 'debugger', group: [:development, :test]

【问题讨论】:

    标签: ruby-on-rails-4 passenger


    【解决方案1】:

    我遇到了完全相同的问题。我花了一个小时才弄明白。

    No such file or directory - config.ru
    

    这一行告诉你问题。它找不到“config.ru”文件。我的 config.ru 文件版本如下:

    # This file is used by Rack-based servers to start the application.
    
    require ::File.expand_path('../config/environment',  __FILE__)
    run Broadsheet::Application
    

    对我来说,这个 config.ru 文件位于我的“/home4/USER/rails_apps/APPNAME”文件夹中,因此它可能位于您的“/home4/USER/APPNAME”文件夹中。它是自动生成的,所以不是我自己添加的,但您可能必须这样做。

    由于Passenger 找不到这个config.ru 文件,可能是我指定的文件夹中丢失了它,或者您的“home4/USER/APPNAME/public/.htaccess”文件中有问题,尤其是以下行:

    RackBaseURI /home4/USER/APPNAME
    

    这是Passenger 似乎用来查找config.ru 文件的目录。我会仔细检查以确保该行在某处没有错字。


    作为旁注,目前我已经让乘客错误消失了,但我仍然无法获得任何视图或任何内容,除了公用文件夹中的静态页面显示或不给我 404 未找到错误。

    【讨论】:

    • 感谢您的回复,但这实际上并没有解决我的问题。我认为我的 cpanel 不支持 rails4,但它适用于我的 rails3 应用程序。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-09-27
    • 1970-01-01
    • 2011-03-31
    • 1970-01-01
    相关资源
    最近更新 更多