LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Server
User Name
Password
Linux - Server This forum is for the discussion of Linux Software used in a server related context.

Notices


Reply
  Search this Thread
Old 07-12-2014, 10:03 AM   #1
audiodef
LQ Newbie
 
Registered: Sep 2008
Posts: 12

Rep: Reputation: 0
Need to password protect Apache subdir


I need to password protect an Apache subdir with HTTP authentication of some kind. I don't really care if it's basic auth or MySQL auth. I just need to keep the public from being able to see a specific subdir of a public site.

My server OS is Ubuntu Server. I've tried posting to their forums, but that didn't help much. I've tried a few things already, but basically, when I think I've done it correctly, I get an HTTP auth dialog, enter the correct user/pass, and I get:

Code:
Unauthorized

This server could not verify that you are authorized to access the document requested. Either you supplied the wrong credentials (e.g., bad password), or your browser doesn't understand how to supply the credentials required.
What I've tried so far is to edit my vhost conf like so:

Code:
<VirtualHost *:80>
    ServerAdmin (email)
    ServerName (domain).com
    ServerAlias www.(domain).com
    DocumentRoot /var/www/(dir)
    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined
<Directory /var/www/(dir)/(subdir)>
        AuthType Basic
        AuthName "Authentication Required"
        AuthUserFile "/path/to/authfile"
        Require valid-user
        Order allow,deny
        Allow from all
</Directory>
</VirtualHost>
I don't see anything wrong with this, and I'm hoping someone can tell me why I'm getting the Unauthorized error and what I should to do fix it. (I have correctly created the authfile with htpasswd, as well.)

Last edited by audiodef; 07-12-2014 at 10:07 AM.
 
Old 07-12-2014, 12:43 PM   #2
bathory
LQ Guru
 
Registered: Jun 2004
Location: Piraeus
Distribution: Slackware
Posts: 13,163
Blog Entries: 1

Rep: Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032
Quote:
I don't see anything wrong with this, and I'm hoping someone can tell me why I'm getting the Unauthorized error and what I should to do fix it. (I have correctly created the authfile with htpasswd, as well.)
Your config looks correct. What do the apache logs say?
 
Old 07-13-2014, 08:11 PM   #3
audiodef
LQ Newbie
 
Registered: Sep 2008
Posts: 12

Original Poster
Rep: Reputation: 0
The log says

Code:
[Sun Jul 13 21:13:16.809158 2014] [:error] [pid 17914] No requires line available

Last edited by audiodef; 07-13-2014 at 08:13 PM.
 
Old 07-14-2014, 01:56 AM   #4
bathory
LQ Guru
 
Registered: Jun 2004
Location: Piraeus
Distribution: Slackware
Posts: 13,163
Blog Entries: 1

Rep: Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032
Quote:
Originally Posted by audiodef View Post
The log says

Code:
[Sun Jul 13 21:13:16.809158 2014] [:error] [pid 17914] No requires line available
Well. as I told you your config looks correct. On the other hand the error above, comes from mod_auth_mysql, so that makes me think that there are some remains of it in the configuration, or perhaps in a .htaccess file.
 
Old 07-14-2014, 12:29 PM   #5
audiodef
LQ Newbie
 
Registered: Sep 2008
Posts: 12

Original Poster
Rep: Reputation: 0
auth_mysql is required for other things, so I can't troubleshoot by disabling it. I've reported this as a bug to Ubuntu Server (14.04) and I'm SERIOUSLY thinking of blowing away my entire server setup and going with a distro that, well, actually works.
 
Old 07-14-2014, 03:14 PM   #6
rubanek
LQ Newbie
 
Registered: Apr 2008
Location: MD
Distribution: CentOS, Fedora
Posts: 23
Blog Entries: 1

Rep: Reputation: 1
I'll bet you your version of Apache is 2.4.

Apache changed the directive to secure directories from the "Allow/Deny" scheme to a new "Requires" scheme when the jumped from 2.2 to 2.4. Do a google search for "Apache 2.4" access control.

I found this link: http://httpd.apache.org/docs/current/howto/access.html

There is says the following:

Quote:
The Allow, Deny, and Order directives, provided by mod_access_compat, are deprecated and will go away in a future version. You should avoid using them, and avoid outdated tutorials recommending their use.
You need a requires directive like so:

Quote:
Require all granted
Hence your error message of:

Quote:
No requires line available

Last edited by rubanek; 07-14-2014 at 03:19 PM.
 
Old 07-14-2014, 04:21 PM   #7
audiodef
LQ Newbie
 
Registered: Sep 2008
Posts: 12

Original Poster
Rep: Reputation: 0
I appreciate the replies. :-)

I went with an entirely different solution, as Ubuntu clearly has a bug in their setup and I can't wait around for a fix. :-)
 
Old 07-15-2014, 03:01 AM   #8
bathory
LQ Guru
 
Registered: Jun 2004
Location: Piraeus
Distribution: Slackware
Posts: 13,163
Blog Entries: 1

Rep: Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032
Quote:
Originally Posted by audiodef View Post
I appreciate the replies. :-)

I went with an entirely different solution, as Ubuntu clearly has a bug in their setup and I can't wait around for a fix. :-)
It's not actually a bug. Apache has dropped mod_auth_mysql in favor of mod_authn_dbd and apparently Ubuntu suffers from this.
Have a look here for more details

Regards
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Password protect a web folder on apache andy1974 Linux - Security 13 05-15-2009 01:28 AM
Apache and Password Protect Folders adrianc.grigoras Linux - Software 1 03-13-2009 02:09 AM
Password protect apache home directories paul_mat Linux - Networking 3 04-28-2006 12:36 AM
LXer: Password protect your website in Apache webserver LXer Syndicated Linux News 0 02-25-2006 09:16 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Server

All times are GMT -5. The time now is 05:59 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration