apache 如何拒绝从php阅读顶级目录

x3naxklr  于 2022-11-16  发布在  Apache
关注(0)|答案(1)|浏览(117)

我刚刚在我的服务器上添加了新的VirtualHost。(在config..下面)如何才能禁止浏览顶级目录(例如:opendir('../../public_html/another_site/'))?我应该在配置中添加什么?我想要单独的站点目录。也许是错误的方式?php / apache config?

<VirtualHost *:80>
    ServerName mysite.pl
    ServerAlias www.mysite
    DocumentRoot /var/www/public_html/mysite

    <Directory /var/www/public_html/mysite>
        Options Indexes FollowSymLinks
        AllowOverride All
        Require all granted
    </Directory>

    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined

    <IfModule mod_dir.c>
        DirectoryIndex index.php index.pl index.cgi index.html index.xhtml index.htm index.php5
    </IfModule>

</VirtualHost>
n6lpvg4x

n6lpvg4x1#

我刚刚找到了一个很好的解决方案。根据网站“https://cwiki.apache.org/confluence/pages/viewpage.action?pageId=115522526“,我添加了php_admin_value open_basedir /srv/web/domain.tld/:/usr/share/pear/

<VirtualHost *:80>
        ServerAdmin admin@domain.tld
        
        DocumentRoot /srv/web/domain.tld/htdocs
        ServerName domain.tld

        php_admin_value open_basedir /srv/web/domain.tld/:/usr/share/pear/
        php_admin_value upload_tmp_dir /srv/web/domain.tld/
        php_admin_value session.safe_path /srv/web/domain.tld/sessions/
        
        <Directory /srv/web/domain.tld/htdocs>
                php_admin_flag engine on
                AllowOverride AuthConfig FileInfo
                Order allow,deny
                allow from all
        </Directory>
</VirtualHost>

相关问题