部署一个带有乘客的 sinatra 应用程序仅给出 404,页面未找到。然而,一个简单的机架应用程序就可以工作

发布于 2024-09-04 05:57:15 字数 1497 浏览 3 评论 0原文

我已经在 apache 2 上正确(或者可能没有)安装了 guest。Rack 可以工作,但是 sinatra 一直给出 404。

这是有效的: config.ru

#app = proc do |env|
  return [200, { "Content-Type" => "text/html" }, "hello <b>world</b>"]  
end
run app

这也是有效的: 使用 ruby​​ app.rb 运行 app.rb(见下文),然后查看 localhost:4567/about 和/

重新启动应用程序,给我一个正确的 hello world。 w00t。

但是辛纳屈进入了大楼: config.ru

require 'rubygems'
require 'sinatra'

root_dir = File.dirname(__FILE__)

set :environment, ENV['RACK_ENV'].to_sym
set :root,        root_dir
set :app_file,    File.join(root_dir, 'app.rb')
disable :run

run Sinatra::Application

app.rb

require 'rubygems'
require 'sinatra'

get '/' do 
 "Hallo wereld!"
end

get '/about' do
 "Hello world, it's #{Time.now} at the server!"
end

这不断给出 404。 /var/logs/apache2/error.log 将这些正确地列为“404”,其中有一些让我担心的

83.XXXXXXXXX - - [30/May/2010 16:06:52] "GET /about " 404 18 0.0007
83.XXXXXXXXX - - [30/May/2010 16:06:56] "GET / " 404 18 0.0007

事情:让我担心的是 / 和 /about 之后的空格。 apache 或 sinatra 会寻找 /[space],例如 /%20 吗?

如果有人知道这个问题与什么相关,也许是一个已知的错误(我找不到)或一个已知的陷阱? 也许我只是愚蠢并理解了“这一切都错了?”

否则,关于在哪里获取、读取或记录有关运行机架、sinatra 或乘客应用程序的更多开发人员数据的任何提示也会有所帮助:例如,查看 sinatra 正在寻找什么。

其他一些信息: 运行 ubuntu 9.04、apache2-mm-prefork (deb)、mod_php5、ruby 1.8.7、passenger 2.2.11、sinatra 1.0

I have correctly (or prbably not) installed passenger on apache 2. Rack works, but sinatra keeps giving 404's.

Here is what works:
config.ru:

#app = proc do |env|
  return [200, { "Content-Type" => "text/html" }, "hello <b>world</b>"]  
end
run app

Here is what works too:
Running the app.rb (see below) with ruby app.rb and then looking at localhost:4567/about and /

restarting the app, gives me a correct hello world. w00t.

But then there is the sinatra entering the building:
config.ru

require 'rubygems'
require 'sinatra'

root_dir = File.dirname(__FILE__)

set :environment, ENV['RACK_ENV'].to_sym
set :root,        root_dir
set :app_file,    File.join(root_dir, 'app.rb')
disable :run

run Sinatra::Application

and an app.rb

require 'rubygems'
require 'sinatra'

get '/' do 
 "Hallo wereld!"
end

get '/about' do
 "Hello world, it's #{Time.now} at the server!"
end

This keeps giving 404s.
/var/logs/apache2/error.log lists these correctly as "404" with something that worries me:

83.XXXXXXXXX - - [30/May/2010 16:06:52] "GET /about " 404 18 0.0007
83.XXXXXXXXX - - [30/May/2010 16:06:56] "GET / " 404 18 0.0007

The thing that worried me, is the space after the / and the /about. Would apache or sinatra go looking for /[space], like /%20?

If anyone knows what this problem relates to, maybe a known bug (that I could not find) or a known gotcha?
Maybe I am just being stupid and getting "it all wrong?"

Otherwise any hints on where to get, read or log more developers data on a running rack, sinatra or passenger app would be helpfull too: to see what sinatra is looking for, for example.

Some other information:
Running ubuntu 9.04, apache2-mm-prefork (deb), mod_php5, ruby 1.8.7, passenger 2.2.11, sinatra 1.0

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

〆凄凉。 2024-09-11 05:57:15

您没有在 app.rb 中加载路由。为此,请在 config.ru 中将 require 'sinatra' 替换为 require File.join(File.dirname(__FILE__), 'app.rb')

root_dir = File.dirname(__FILE__)
app_file = File.join(root_dir, 'app.rb')
require app_file

set :environment, ENV['RACK_ENV'].to_sym
set :root,        root_dir
set :app_file,    app_file
disable :run

run Sinatra::Application

set :app_file 不会为您加载它们。

You are not loading the routes in app.rb. To do this, replace require 'sinatra' with require File.join(File.dirname(__FILE__), 'app.rb') in config.ru.

root_dir = File.dirname(__FILE__)
app_file = File.join(root_dir, 'app.rb')
require app_file

set :environment, ENV['RACK_ENV'].to_sym
set :root,        root_dir
set :app_file,    app_file
disable :run

run Sinatra::Application

set :app_file won't load them for you.

≈。彩虹 2024-09-11 05:57:15

只需将 require sinatra 替换为 require 'app' 即可。

Just substitute the require sinatra with a require 'app' and you're set to go.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文