Linode Forum
Linode Community Forums
 FAQFAQ    SearchSearch    MembersMembers      Register Register 
 LoginLogin [ Anonymous ] 
Post new topic  Reply to topic
Author Message
PostPosted: Sun Apr 10, 2011 7:44 pm 
Offline
Senior Newbie

Joined: Fri Apr 08, 2011 4:46 pm
Posts: 12
I have nginx + php-fpm running on debian 6 and all is well.

However, I want to take www.example.com/wiki and password-protect it using basic auth. In apache, I'd drop in a .htaccess, but for nginx, I need to create a location rule.

I have this rule:

Code:
location ~ \.php$ {


but when I create this:

Code:
location ~ /wiki {
    auth_basic  "Restricted";
    auth_basic_user_file  /some/path/wiki.users;
  }


everything in /wiki breaks. I suspect what's happening is that nginx matches the first rule and never gets to the second. But a rule like this doesn't change things:

Code:
location ~ /wiki.*\.php$ {

Strangely, I see errors like this in the site's nginx's log:
Code:
2011/04/10 14:52:05 [error] 1826#0: *9 open() "/usr/local/nginx/html/
wiki/skins/common/images/poweredby_mediawiki_88x31.png" failed (2: No
such file or directory), client: x.x.x.x, server: example.org,
request: "GET /wiki/skins/common/images/poweredby_mediawiki_88x31.png
HTTP/1.1", host: "www.example.org", referrer: "http://www.example.org/
wiki/index.php?title=Main_Page"


...which makes no sense because the string '/usr/local/nginx' doesn't exist anywhere in /etc/nginx or /etc/php (grep -R -i), so where would php-fpm be picking that up from?

If I turn off auth_basic, everything works perfectly. But I need to password-protect some directories...so...how? I'm surprised it's this difficult when it's so easy in Apache.


Top
   
 Post subject:
PostPosted: Sun Apr 10, 2011 11:40 pm 
Offline
Senior Newbie

Joined: Wed Mar 02, 2011 9:56 pm
Posts: 7
Just a wild guess, but do you have your root set inside of a location block?


Top
   
 Post subject:
PostPosted: Mon Apr 11, 2011 12:02 am 
Offline
Senior Newbie

Joined: Fri Apr 08, 2011 4:46 pm
Posts: 12
texascrane wrote:
Just a wild guess, but do you have your root set inside of a location block?


Yes.

At the moment, what I did was setup wiki.example.org separately from www.example.org as a separate site. Then I put the auth_basic and auth_basic_user_file in both the .php-matching location and the / location.

That works fine...I'm not sure what the 100% correct way to do this is, though.

Apache was easier...too bad it takes so much RAM :-)


Top
   
 Post subject:
PostPosted: Mon Apr 11, 2011 1:22 pm 
Offline
Senior Newbie

Joined: Wed Mar 02, 2011 9:56 pm
Posts: 7
raindog308 wrote:
texascrane wrote:
Just a wild guess, but do you have your root set inside of a location block?


Yes.



That's probably your problem. You need to move the root location into the server block. Otherwise you need to duplicate your php location matching block inside of the restricted block as you found out.


Top
   
Display posts from previous:  Sort by  
Post new topic  Reply to topic


Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  
RSS

Powered by phpBB® Forum Software © phpBB Group