apache basic auth across multiple virtualhosts
<p>I have a few staging sites as virtual hosts on a server, plus a couple of public-facing virtual host sites.  The stating sites are all under a single directory (e.g., <code>/var/www/staging-sites/[site-document-root]</code>).</p>

<p>Up to now I've been configuring HTTP Basic Auth for each virtual host, but it seems like there should be a way to do it once for all of them.</p>

<p>The question "<a href="https://stackoverflow.com/questions/9272134/apache-global-basic-auth?newreg=1b9306b1f6aa4f578770893efb5e3882">apache global basic auth</a>" indicates that I could place Basic Auth directives in a <code>&lt;Directory /var/www/staging-sites&gt;</code> container in the main apache config file, but doing so doesn't cause the browser to prompt for credentials.</p>

<p>Here's the output of <code>tail -n 7 /etc/apache2/apache2.conf</code>:</p>

<pre><code>&lt;Directory "/var/www/staging-sites/"&gt;
  AuthType Basic
  AuthName "Authentication Required"
  AuthBasicProvider file
  AuthUserFile /var/www/staging-sites/.htpasswd
  Require valid-user
&lt;/Directory&gt;
</code></pre>

<ul>
<li>I've verified that /var/www/staging-sites/.htpasswd exists, and that the site foo.mydomain.com uses the Document Root /var/www/staging-sites/foo.  </li>
<li>I've restarted apache to ensure the new config gets loaded.</li>
</ul>

<p>However, when I open <a href="http://foo.mydomain.com" rel="nofollow noreferrer">http://foo.mydomain.com</a>, the site is displayed without prompting for Basic Auth credentials.</p>

<p>What am I doing wrong?</p>