Apache2:禁止访问您无权访问此服务器上的/ dir /


17

我可以访问localhost但不能访问子目录index.html

我的default conf样子:

<VirtualHost *:80>
ServerAdmin webmaster@localhost

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

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

ErrorLog ${APACHE_LOG_DIR}/error.log

# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel warn

CustomLog ${APACHE_LOG_DIR}/access.log combined

即使在允许read/edit/write访问目录之后,其也会显示“禁止访问”错误。在论坛上尝试了所有可能的方法,但没有成功。任何人都有解决方案。

在上面之间,我尝试了一些sub directory访问权限:

<Directory /var/www/*/>
    Allow from None
    Order allow,deny
</Directory>

请建议我可能的解决方案。谢谢!

Answers:


17

让我们明确虚拟主机:

<VirtualHost *:80>
    ServerAdmin webmaster@localhost

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

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

    ErrorLog ${APACHE_LOG_DIR}/error.log

    # Possible values include: debug, info, notice, warn, error, crit,
    # alert, emerg.
    LogLevel warn

    CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

然后确保您设置正确的权限,如下所示:

sudo adduser <username> www-data
sudo chown -R www-data:www-data /var/www
sudo chmod -R g+rw /var/www

我是这样 还是一样。重新启动Apache。我应该尝试在apache.conf中进行修改吗?
Shobhit Sharma,

这是东西。我试图将根目录更改为我的主文件夹索引,并且该目录仍指向/ var / www。要找到正确的conf文件。
Shobhit Sharma,

@ShobhitSharma请尝试更新的。如果尝试将虚拟主机目录定位到主文件夹,则应仅创建其他虚拟主机更改,DocumentRoot /var/www而不是修改默认虚拟主机更改。
阿楚

太好了 只需添加www-data用户。现在我所有的本地网络用户都可以使用该内容
DearDhruv
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.