Basic auth for specific controller


we would like to provide basic auth for specific rails controllers
(/stats …) with nginx (and passenger).

We tried the following.

server {
listen 80;
root /home/deployer/myapp/public;
passenger_enabled on;
rails_env production;

location ~ ^/(admin|awstats|webalizer|stats) {
auth_basic “Restricted”;
auth_basic_user_file /etc/nginx/basic.auth;


This results in the following error:

2010/10/18 11:18:20 [error] 31331#0: *4 open()
“/home/deployer/myapp/public/stats” failed (2: No such file or
directory), client: xx.xx.xx.xx, server:, request: “GET
/stats HTTP/1.1”, host: “

Nginx responds with a 404 page.

It seems like the server tries to serve static files

Any ideas?

Thanks in advance!



You have to set ‘passenger_enabled on’ within the location directive as

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs