我想用基本的httpauthentication来保护我新部署的Rails 3应用程序。 它运行在最新的Nginx / Passenger上,我使用下面的Nginx指令来保护Web根目录:
location = / { auth_basic "Restricted"; auth_basic_user_file htpasswd; }
htpasswd文件是使用Apache htpasswd utililty生成的。 但是,input正确的用户名和密码后,我将转到403 Forbidden错误页面。 分析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目录的内容。 我怎样才能正确configuration这样的Rails应用程序启动后,我进入我的login信息?
您需要在位置块中重新指定passenger_enabled。
你可以让Rails处理认证
# 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
(或Rails 3中的applicaion.rb
中设置config.serve_static_assets = true
,这样public
静态资源就可以通过同一个过滤器。
检查你的Nginx错误日志。 403
意味着你的密码文件路径错误。