Localhost 抛出禁止错误,一些目录只是空白

Localhost throws forbidden error and some directories are just blank

我使用发行版附带的捆绑包安装了 lamp 堆栈; bunsen-meta-lamp.

lamp 安装后 apparmor 安装并激活了它。根目录已更改为 /var/www/var/www/ 及其子目录具有 %USER:$USER 读写权限(甚至尝试过 755)。 a2enmod module 已启用。每次 mod、Apache 服务重新启动后。

结果:Localhost 确实列出了项目文件夹。但是,有些项目会在浏览器中打开;而其他人则抛出一个禁止的错误。浏览器将子目录显示为空白页。

尝试了 here, and here 中提到的方法,但没有结果。

这是我的 3 个 .conf 文件。

$ /etc/apache2/sites-available/000-default.conf

<VirtualHost *:80>

        ServerAdmin webmaster@localhost
        DocumentRoot /var/www/
        ServerName server_domain_name_or_IP

        DocumentRoot /var/www
        <Directory />
                Options FollowSymLinks
                AllowOverride All
        </Directory>
        <Directory /var/www/>
                Options Indexes FollowSymLinks MultiViews
                AllowOverride All
                Order allow,deny
                allow from all
        </Directory>

        ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
        <Directory "/usr/lib/cgi-bin">
                AllowOverride All
                Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
                Order allow,deny
                Allow from all
        </Directory>

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

</VirtualHost>

# vim: syntax=apache ts=4 sw=4 sts=4 sr noet



$ cat /etc/apache2/apache2.conf    
#ServerRoot "/etc/apache2"
#
#Mutex file:${APACHE_LOCK_DIR} default
#
DefaultRuntimeDir ${APACHE_RUN_DIR}
#
PidFile ${APACHE_PID_FILE}
#
Timeout 300
#
KeepAlive On
#
MaxKeepAliveRequests 100
#
KeepAliveTimeout 5
#
User ${APACHE_RUN_USER}
Group ${APACHE_RUN_GROUP}
#
HostnameLookups Off
#
ErrorLog ${APACHE_LOG_DIR}/error.log
#
LogLevel warn
#
IncludeOptional mods-enabled/*.load
IncludeOptional mods-enabled/*.conf
#
Include ports.conf

<Directory />
    Options FollowSymLinks
    AllowOverride None
    Require all granted
</Directory>

<Directory /usr/share>
    AllowOverride None
    Require all granted
</Directory>

<Directory /var/www/>
    Options Indexes FollowSymLinks
    AllowOverride None
    Require all granted
</Directory>

#<Directory /srv/>
#   Options Indexes FollowSymLinks
#   AllowOverride None
#   Require all granted
#</Directory>
#
AccessFileName .htaccess
#
<FilesMatch "^\.ht">
    Require all denied
</FilesMatch>
#
LogFormat "%v:%p %h %l %u %t \"%r\" %>s %O \"%{Referer}i\" \"%{User-Agent}i\"" vhost_combined
LogFormat "%h %l %u %t \"%r\" %>s %O \"%{Referer}i\" \"%{User-Agent}i\"" combined
LogFormat "%h %l %u %t \"%r\" %>s %O" common
LogFormat "%{Referer}i -> %U" referer
LogFormat "%{User-agent}i" agent
#
IncludeOptional conf-enabled/*.conf
#
IncludeOptional sites-enabled/*.conf

# vim: syntax=apache ts=4 sw=4 sts=4 sr noet



cat /etc/apache2/sites-enabled/000-default.conf
<VirtualHost *:80>

        ServerAdmin webmaster@localhost
        DocumentRoot /var/www/
        ServerName server_domain_name_or_IP

        DocumentRoot /var/www
        <Directory />
                Options FollowSymLinks
                AllowOverride All
        </Directory>
        <Directory /var/www/>
                Options Indexes FollowSymLinks MultiViews
                AllowOverride All
                Order allow,deny
                allow from all
        </Directory>

        ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
        <Directory "/usr/lib/cgi-bin">
                AllowOverride All
                Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
                Order allow,deny
                Allow from all
        </Directory>

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

</VirtualHost>    
# vim: syntax=apache ts=4 sw=4 sts=4 sr noet

解决了问题:

sudo chown -R $USER:$USER /var/www/folder-name

sudo chmod -R 755 /var/www

授予权限

或者试试这个

转到etc/apache2/apache2.conf

您会发现一个包含正常目录和权限的块:

<Directory /var/www/>
Options Indexes FollowSymLinks
AllowOverride None
Require all granted
</Directory>

您可以复制它,但将“/var/www/”更改为新目录

然后从终端:sudo service apache2 restart