为什么.htaccess没有阻止apache中的文件夹?

时间:2016-11-18 11:08:42

标签: apache .htaccess ubuntu

我试图阻止在apache中直接访问特定文件夹。

我的文件夹结构: / var / www / html - page.html                - 私人文件夹                   - css                  -jss

我正在尝试使用密码保护私人文件夹。

我完成了以下步骤:

1。在私人文件夹中创建.htacess文件。

.htacess文件:

AuthType Basic
AuthName "Restricted Content"
AuthUserFile /etc/apache2/.htpasswd
Require valid-user

2。使用htpasswd

在/ etc / apache2中创建一个.htpasswd文件
  1. 现在我在/etc/apache2/apache2.conf中更改了一些规则。
  2. 但是当我访问10.0.0.1/private时,我可以使用密码浏览此目录。

    <Directory />
        Options FollowSymLinks
        AllowOverride None
        Require all denied
    </Directory>
    
    <Directory /usr/share>
        AllowOverride None
        Require all granted
    </Directory>
    
    <Directory /var/www/>
        Options Indexes FollowSymLinks
        AllowOverride AuthConfig
        AllowOverride All
        Require all granted
    </Directory>
    
    
    <Directory /var/www/>
         Options ExecCGI
         AllowOverride None
         Order allow,deny
         Allow from all
         AddHandler cgi-script .cgi
    </Directory>
    
    <Directory /var/www/>
    Options All
    </Directory>
    
    
    AccessFileName .htaccess
    

    还有其他问题吗?我为.htaccess.htpasswd

    设置了写入权限
    sudo chmod 777 /var/www/html/private/.htaccess
    

    sudo chmod 777 /etc/apache2/.htaccess
    

    有什么建议吗?

1 个答案:

答案 0 :(得分:1)

首先,如果您可以编辑.conf文件,则不应使用.htaccess

对于您的问题,当AllowOverride指令设置为None时,.htaccess文件将被完全忽略。在这种情况下,服务器甚至不会尝试读取文件系统中的.htaccess文件。 您可以尝试将其添加到/etc/apache2/apache2.conf

<Directory "/var/www/html/private">
    AuthType Basic
    AuthName "Restricted Content"
    AuthUserFile /etc/apache2/.htpasswd
    Require valid-user
</Directory>