# Basic auth for specific controller

**URL:** <https://www.ruby-forum.com/t/basic-auth-for-specific-controller/197651>\
**Category:** NGINX\
**Created:** [October 18, 2010, 12:07pm UTC](https://www.ruby-forum.com/t/basic-auth-for-specific-controller/197651 "2010-10-18T12:07:55Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![okkezSS](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/o/85f322/32.png) [@okkezSS](https://www.ruby-forum.com/u/okkezSS)\
**Post date:** [October 18, 2010, 12:07pm UTC](https://www.ruby-forum.com/t/basic-auth-for-specific-controller/197651/1 "2010-10-18T12:07:55Z")

</div>

Hi,

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

We tried the following.

server {  
listen 80;  
server\_name [www.myapp.de](http://www.myapp.de);  
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: [www.myapp.de](http://www.myapp.de), request: “GET  
/stats HTTP/1.1”, host: “[www.myapp.de](http://www.myapp.de)”

Nginx responds with a 404 page.

It seems like the server tries to serve static files  
(/home/deployer/myapp/public/stats).

Any ideas?

Thanks in advance!

Peter

---

<div class="post-metadata">

**Author:** ![peterk](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/7993a0/32.png) [@peterk](https://www.ruby-forum.com/u/peterk)\
**Post date:** [October 19, 2010, 3:11pm UTC](https://www.ruby-forum.com/t/basic-auth-for-specific-controller/197651/2 "2010-10-19T15:11:51Z")

</div>

Solved!

You have to set ‘passenger\_enabled on’ within the location directive as  
well.
