如何防止访问Apache2中的文件夹并允许PHP中的访问?

问题描述 投票:0回答:1

我知道这个问题已经问过几次了,但是我尝试了很多组合,但似乎都没有用。

这是我的apache.conf文件中的一部分:

<Directory />
    Options None
    AllowOverride None
    Require all denied
</Directory>

<Directory /var/www/>
    Options -Indexes -FollowSymLinks -ExecCGI
    AllowOverride Limit

    # Restrict access controls to all HTTP methods except the named ones (GET)
    <LimitExcept GET>
        Require all denied
    </LimitExcept>

    # Restrict access controls to the GET HTTP method, by only allowing
    # requests coming from the specified IPs
    <Limit GET>
        # Clients in the specified IP address ranges can access the resource,
       Require ip <list of IPs here>
    </Limit>
</Directory>

如何配置apache.conf文件,以便无法从外部访问目录/var/www/html/somefolder,但可以从服务器上运行的PHP脚本访问该目录?

我尝试将其添加到上面的代码下面:

<Directory /var/www/html/denied_directory>
    Order allow,deny
    <Files some_private_file.txt>
        Order deny,allow
    </Files>
</Directory>

我也尝试过FilesLocation,但是它们要么不起作用(也就是说,来自外部的客户端仍然能够访问该文件夹),要么它们起作用了[[太好了(即, PHP脚本无法访问文件夹和文件。

在此先感谢您花一些时间来帮助我的人。
php directory apache2 access apache2.4
1个回答
0
投票
不移动目录。

<Directory /var/www/html/denied_directory> AllowOverride None Require all denied </Directory>

© www.soinside.com 2019 - 2024. All rights reserved.