2012-03-27 55 views
0

目前我的主目錄和子目錄都有密碼保護,但是我希望僅在從本地子網連接時從外部IP地址和密碼釋放時才需要密碼保護。當使用Apache從外部IP訪問時,密碼保護目錄

目前/etc/apache2/sites-available/default看起來是這樣的:

<VirtualHost *:80> 
     ServerAdmin [email protected] 

     DocumentRoot /var/www 
     <Directory /> 
       Options FollowSymLinks 
       AllowOverride None 
     </Directory> 
     <Directory /var/www/> 
       Options Indexes FollowSymLinks MultiViews 
       AllowOverride None 
       Order allow,deny 
       allow from all 
     </Directory> 

     ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/ 
     <Directory "/usr/lib/cgi-bin"> 
       AllowOverride None 
       Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch 
       Order allow,deny 
       Allow from all 
     </Directory> 

     ErrorLog ${APACHE_LOG_DIR}/error.log 

     # Possible values include: debug, info, notice, warn, error, crit, 
     # alert, emerg. 
     LogLevel warn 

     CustomLog ${APACHE_LOG_DIR}/access.log combined 

    Alias /doc/ "/usr/share/doc/" 
    <Directory "/usr/share/doc/"> 
     Options Indexes MultiViews FollowSymLinks 
     AllowOverride None 
     Order deny,allow 
     Deny from all 
     Allow from 127.0.0.0/255.0.0.0 ::1/128 
    </Directory> 

    <Location/> 
     AuthType Digest 
     AuthName "intranet" 
     AuthDigestDomain /var/www/ http://10.1.2.2 

     AuthDigestProvider file 
     AuthUserFile /etc/apache2/passwords 
     Require user user1 
     SetEnv R_ENV "/var/www" 
    </Location> 

    <Location /dir1> 
     AuthType Digest 
     AuthName "dir" 
     AuthDigestDomain /var/www/dir1/ http://10.1.2.2/dir1 

     AuthDigestProvider file 
     AuthUserFile /etc/apache2/passwords 
     Require user user2 
     SetEnv R_ENV "/var/www/dir1" 
    </Location> 

    <Location /dir2> 
     AuthType Digest 
     AuthName "dir" 
     AuthDigestDomain /var/www/ http://10.1.2.2/dir2 

     AuthDigestProvider file 
     AuthUserFile /etc/apache2/passwords 
     Require user user2 
     SetEnv R_ENV "/var/www/dir2" 
    </Location> 

</VirtualHost> 

我有一個戰利品在Apache's documentation on auth但不能做的我怎麼會那麼實現與密碼保護意識。

回答

1

的搜索提出這有點http://www.askapache.com/htaccess/apache-authentication-in-htaccess.html

基本上改變了這一點:

<Location/> 
    AuthType Digest 
    AuthName "intranet" 
    AuthDigestDomain /var/www/ http://10.1.2.2 

    AuthDigestProvider file 
    AuthUserFile /etc/apache2/passwords 
    Require user user1 
    SetEnv R_ENV "/var/www" 
</Location> 

這樣:

<Location /> 
    Order deny,allow 
    Deny from all 
    AuthType Digest 
    AuthName "intranet" 
    AuthDigestDomain /var/www/ http://10.1.2.2 

    AuthDigestProvider file 
    AuthUserFile /etc/apache2/passwords 
    Require valid-user 
    SetEnv R_ENV "/var/www" 
    Allow from 10.1.2.0/24 
    Satisfy Any 
</Location> 

測試,這一切都平穩運行。