我正在尝试找出保护我的暂存环境的最佳方法。目前我在同一台服务器上同时运行登台和生产。
我能想到的两个选择是:
使用 Rails 摘要认证
我可以把这样的东西放在 application_controller.rb
# Password protection for staging environment
if RAILS_ENV == 'staging'
before_filter :authenticate_for_staging
end
def authenticate_for_staging
success = authenticate_or_request_with_http_digest("Staging") do |username|
if username == "staging"
"staging_password"
end
end
unless success
request_http_digest_authentication("Admin", "Authentication failed")
end
end
这是从Ryan Daigle 的博客中摘录的。我在最新的 Rails 2.3 上运行,所以我应该摆脱他们对此的安全问题。
使用 Web 服务器身份验证
我也可以使用 .htaccess 或 apache 权限来实现这一点,但是它使我的服务器配置稍微复杂一些(我使用的是 Chef,并且需要不同的 apache 配置用于暂存/生产)。
现在我已经实现了第一个并且正在运行,你觉得它有什么问题吗?我错过了什么明显的东西吗?提前致谢!