Securing Your Web Pages with Apache Page 7
But how do you turn on access control in the first place? Just as you apply any other Apache directive: by having the directives appear in the appropriate scope. For example:
<Directory /usr/local/web/htdocs/finance> AuthName Finance AuthType Basic AuthUserFile /usr/local/web/apache/auth/.htpasswd-finance Require valid-user </Directory>
This will protect the
financesubdirectory and all files and subdirectories in it any below it. Other directories, such as
products, remain unaffected.
<Directory>containers are all very well, but what if you want to protect only a single file? Or perhaps a document that isn't mapped to the filesystem, like the output from
mod_status? The answer remains the same: use the appropriate scoping directives (such as
<Location>) to apply the security measures to the items you want protected.
Like almost all other Apache configuration details, the security directives that apply to a particular document or directoy may be inherited from the parent, or possibly even further up the tree. This means that at each level you need only supply those directives that are different. The following two fragments are equivalent:<Directory /usr/local/web/htdocs/finance> AuthName "Finance Department" AuthType Basic AuthUserFile /usr/local/web/apache/auth/.htpasswd-finance Require valid-user </Directory> <Directory /usr/local/web/htdocs/finance/strategy> AuthName "Finance Department" AuthType Basic AuthUserFile /usr/local/web/apache/auth/.htpasswd-finance Require user susan bob </Directory> <Directory /usr/local/web/htdocs/finance> AuthName "Finance Department" AuthType Basic AuthUserFile /usr/local/web/apache/auth/.htpasswd-finance Require valid-user </Directory>
<Directory /usr/local/web/htdocs/finance/strategy> Require user susan bob </Directory>
The second fragment takes advantage of the inheritance of the values from the parent directory, and simply restricts the access list to only Bob and Susan.
It's generally not a good idea to make too many assumptions when dealing with security matters, so even though inheritance can seem to make your life easier by not requiring you to duplicate directives all over the place, this might be an illusion. Just wait until you see how complicated your life becomes when all the inherited values become compromised because of a single mistake at a higher level.
A related subject involves determining which of possibly several access control modules has the Final Say on whether access is granted or not. This is covered in a later section.
Requiring a Specific Username
IT Solutions Builder TOP IT RESOURCES TO MOVE YOUR BUSINESS FORWARD
Which topic are you interested in?
What is your company size?
What is your job title?
What is your job function?
Searching our resource database to find your matches...