apache - 在 Apache 2.4 中调试为什么我得到 "You don' t have permission to access”

标签 apache vhosts hosts apache2.4 hosts-file

我正在尝试在 Linux/Ubuntu 中创建本地环境。

我已经安装了 Apache 2.4.7(使用 apt-get)。

我已将/etc/hosts 更改为:

127.0.0.1   example.dev
127.0.0.1   localhost
...

我还在“/etc/apache2/sites-available”中添加了一个文件“example.dev.conf”,如下所示:
<VirtualHost *:80>
    ServerName example.dev
    DocumentRoot "/home/yahya/path/to/projec"
    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined
    <Directory "/home/yahya/path/to/project">
        AllowOverride All
        Require all granted
    </Directory>
</VirtualHost>

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

但是当我转到 example.dev 时,我收到以下消息:

403 Forbidden! You don't have permission to access / on this server.



我还为 <Directory /> 编辑了 apache.conf 部分来自此链接的建议:Forbidden You don't have permission to access / on this serverError message "Forbidden You don't have permission to access / on this server"

从:
<Directory />
    Options FollowSymLinks
    AllowOverride None
    Require all denied
</Directory>


<Directory />
    Options Indexes FollowSymLinks Includes ExecCGI
    AllowOverride All
    Order deny,allow
    Require all granted
</Directory>

我用过a2ensite。但仍然不起作用。

最佳答案

即使解决方案可能不是这样,您也应该首先检查 apache 是否可以访问您的目录。这意味着您的文件夹应该具有“其他人”的读取权限或学习如何在 linux 上配置 acls。

$ ls -la /home/nek
# ...
drwxrwxr-x   6 nek  nek    4096 nov.  19 21:07 MyFolderOfDev

重要的部分是权限的最后一部分:“r-x”。如果您没有类似的东西,请使用以下命令:
$ chmod -R 755 MyFolderOfDev

你的原始配置在我看来不错。如果您与另一个虚拟主机没有冲突,请检查。但这是我的配置,效果很好:
# Defining virtualhost
<VirtualHost *:80>
# This is not needed but seriously recommended
        ServerAdmin contact@moi.com
# This line is your host name (example.dev if you prefere)
        ServerName nekland
# You can add another server name using ServerAlias
    ServerAlias nekland.dev
# Path to your folder
    DocumentRoot /home/nek/Apache/SymfonyProject/web/
# Here are options neeeded to authorizations and I added some classical options
        <Directory /home/nek/Apache/SymfonyProject/web/>
                AllowOverride All
                Options -Indexes +FollowSymLinks +MultiViews
                Require all granted
        </Directory>
# For the error file, exactly like you did
        ErrorLog /var/log/apache2/nekland.err
        LogLevel warn
        CustomLog /var/log/apache2/nekland.log combined
# A little bonus that remove the server signature from http requests
        ServerSignature Off
</VirtualHost>

当然不要忘记每次修改后重新加载apache。
$ sudo service apache2 reload

如果没有任何效果...检查您的日志!这是找出您的请求为何有效的更好方法。

关于apache - 在 Apache 2.4 中调试为什么我得到 "You don' t have permission to access”,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27160209/

相关文章:

php - 如何使用相同的 APC 缓存运行多个 PHP 站点?

Apache 作为反向代理不起作用

php - 如何在 MAMP 中设置环境变量?

apache2 - 使用Apache的VPS上的多个域

dns -/etc/hosts可以配置反向解析吗?

linux - Subversion with Apache 和权限问题

PHP 命名空间与 Phalcon、Vagrant、Apache2 的冲突

ubuntu - 我的 ubuntu 服务器上没有 a2ensite

azure-devops - Azure devops 托管代理可疑主机文件

java - RMI 连接被拒绝