我想使用基本的http身份验证来保护我新部署的Rails3应用程序。它在最新的Nginx/Passenger上运行,我使用以下Nginx指令来保护web根目录:
location = / {
auth_basic "Restricted";
auth_basic_user_file htpasswd;
}
使用Apache htpasswd utililty生成htpasswd文件。但是,在输入正确的用户名和密码后,我将转到403禁止错误页面。分析Nginx错误日志显示:
directory index of "/var/www/mysite/public/" is forbidden, client: 108.14.212.10, server: mysite.com, request: "GET / HTTP/1.1", host: "mysite.com"
显然,我不想列出mysite/public目录的内容。如何正确配置它,以便在我输入登录信息后启动Rails应用程序?
发布于 2010-11-13 21:22:07
您需要在location块中重新指定passenger_enabled。
发布于 2010-11-13 17:40:02
你可以使用let Rails handle the authentication
# application_controller.rb
before_filter :authenticate
protected
def authenticate
authenticate_or_request_with_http_basic do |username, password|
username == "foo" && password == "bar"
end
end
此外,您应该在environment.rb
中设置config.serve_static_assets = true
(或在Rails3中设置applicaion.rb
),以便public
中的静态资产通过相同的过滤器。
发布于 2010-11-13 15:54:50
检查你的Nginx错误日志。403
意味着你把密码文件的路径弄错了。
https://stackoverflow.com/questions/4171454
复制相似问题