当我在AppFog上访问Sinatra应用程序时,会显示“禁止”消息

时间:2012-06-01 06:51:20

标签: ruby sinatra rack paas

我向AppFog上传了一个简单的Sinatra应用程序。它在我的本地机器上运行良好。但在将应用程序上传到AppFog后,当我访问AppFog domain时,会显示包含“禁止”消息的页面。

这些是appFog日志:

====> /logs/stderr.log <====
...
W, [2012-06-01T06:32:54.008426 #28933]  WARN -- : attack prevented by Rack::Protection::IPSpoofing
211.32.146.42 - - [01/Jun/2012 06:32:54] "GET / HTTP/1.1" 403 - 0.0002
10.0.64.157 - - [01/Jun/2012:06:32:54 UTC] "GET / HTTP/1.0" 403 9 - -> /
W, [2012-06-01T06:32:54.393022 #28933]  WARN -- : attack prevented by Rack::Protection::IPSpoofing
211.32.146.42 - - [01/Jun/2012 06:32:54] "GET /favicon.ico HTTP/1.1" 403 - 0.0002
10.0.64.157 - - [01/Jun/2012:06:32:54 UTC] "GET /favicon.ico HTTP/1.0" 403 9 - -> /favicon.ico

我在代码中没有使用Rack::Protection::IPSpoofing,但是我收到了这些错误。 Rack::Utils用于帮助程序块。这会导致问题吗?

我写的唯一Ruby代码如下:

require 'sinatra'
require 'data_mapper'
require 'builder'
require 'sinatra/flash'
require 'sinatra/redirect_with_flash'
require 'haml'

enable :sessions

SITE_TITLE = "Recall"
SITE_DESCRIPTION = "'cause you're too busy to remember"

DataMapper::setup(:default, "sqlite3://#{Dir.pwd}/recall.db")

class Note
  include DataMapper::Resource
  property :id, Serial
  property :content, Text, :required => true
  property :complete, Boolean, :required => true, :default => false
  property :created_at, DateTime
  property :updated_at, DateTime
end

DataMapper.finalize.auto_upgrade!

helpers do
  include Rack::Utils
  alias_method :h, :escape_html
end

get '/' do
  @notes = Note.all :order => :id.desc
  @title = 'All Notes'
  if @notes.empty?
    flash[:error] = 'No notes found. Add your first below.'
  end
  haml :home
end

# ...

您可以查看完整的源代码here

我该如何解决这个问题?感谢您的任何建议。

1 个答案:

答案 0 :(得分:5)

这是一个简单的解决方法,请尝试添加:

set :protection, :except => :ip_spoofing

我们正在修补我们的nginx以解决此问题,但这项工作现在将有所帮助。