【问题标题】:Why .htaccess not blocking Folder in apache?为什么 .htaccess 不阻止 apache 中的文件夹?
【发布时间】:2017-04-02 05:10:56
【问题描述】:

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

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

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

我完成了以下步骤:

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

.htacess 文件:

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

2 。在 /etc/apache2 中使用 htpasswd 创建一个 .htpasswd 文件

  1. 现在我更改了 /etc/apache2/apache2.conf 中的一些规则。

但是当我访问 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

有什么建议吗?

【问题讨论】:

    标签: apache .htaccess ubuntu


    【解决方案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> 
    

    【讨论】:

    • 那么我应该删除.htacess 文件并将此规则包含在apache2.conf 中吗?而且我已经在&lt;Directory /var/www/&gt;中添加了AllowOverride All
    • 对于这个 Auth 问题,从 private/ 文件夹中删除 .htaccess 并将其包含在 .conf 中。如果这是唯一的 .htaccess,您可以将 AllowOverride All 更改为 AllowOverride None。如果还有其他 .htaccess 文件,请将它们的指令移动到 .conf,然后将 AllowOverride All 更改为 AllowOverride None
    • .htaccess 仅用于您无权访问.conf 文件(例如共享主机)的情况
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-07-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-06-17
    • 2023-04-11
    相关资源
    最近更新 更多