apache virtualhost conf文件和授权

时间:2015-04-25 15:23:34

标签: apache .htaccess directory

这是我的conf文件:

<VirtualHost *:80>
    ServerAdmin r0dy@r0dy.net
    ServerName mtc.r0dy.net
    ServerAlias www.mtc.r0dy.net

    DocumentRoot /var/www/mtc
    <Directory />
            Options FollowSymLinks
            AllowOverride None
    </Directory>
    <Directory /var/www/mtc>
            Options Indexes FollowSymLinks MultiViews
            AllowOverride None
            Order allow,deny
            Allow from all
    </Directory>
     <Directory /var/www/mtc/bo>
            AuthName "Restricted Area: BackOffice"
            AuthType Basic
            AuthUserFile /var/www/mtc/bo/.htpasswd
#           AuthGroupFile /dev/null
            require valid-user
    </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>

</VirtualHost>

当我评论<Directory /var/www/mtc/bo>部分时,它不会要求提供凭据 当我取消注释它时,如果我浏览到这个目录,它会要求提供凭证,它可以正常工作 我的问题是,即使我转到/ bo /目录,也要求凭据,我只是浏览到http://mtc.r0dy.net/并且我被阻止了。
对我做错了什么的想法?

1 个答案:

答案 0 :(得分:0)

如果有人遇到同样的问题,我通过在我的目录中添加Allow指令来解决它:

        <Directory />
                Options FollowSymLinks
                #AllowOverride None
                Order allow,deny
                Allow from all
        </Directory>
        <Directory /var/www/mtc>
                Options Indexes FollowSymLinks MultiViews
                #AllowOverride None
                Order allow,deny
                Allow from all
        </Directory>
         <Directory /var/www/mtc/bo>
                Order allow,deny
                Allow from all
                AuthName "Restricted Area: BackOffice"
                AuthType Basic
                AuthUserFile /var/www/mtc/bo/.htpasswd
#               AuthGroupFile /dev/null
                require valid-user
        </Directory>

我不明白为什么它适用于allow指令并且行为奇怪没有,但它现在工作正常。如果有人有解释,欢迎你。