Linux Apache 配置 - 您无权访问/在此服务器上?

标签 linux apache ubuntu apache2

我如何告诉 Apache 指向 127.0.0.1到特定文件夹,如 /var/www/projects/mysite1/

我使用sudo gedit /etc/apache2/apache2.conf这是我的配置:

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

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

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

所以如果我改变/var/www//var/www/projects/mysite1/我尝试访问 http://127.0.0.1/重新启动服务器后,在我的浏览器上出现此错误:

Forbidden

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

Apache/2.4.7 (Ubuntu) Server at 127.0.0.1 Port 80

有什么想法我应该做什么吗?

最佳答案

我认为实现这一目标的最佳方法是创建 VirtualHost。

  1. /etc/apache2/sites-available 中,创建一个 mysite1.conf 文件。在那里,您应该具有以下配置:

    <VirtualHost 127.0.0.1:80>
        ServerName localhost
        ServerAdmin webmaster@localhost
        DocumentRoot /var/www/projects/mysite1/
    
        <Directory /var/www/projects/mysite1/>
            Options Indexes FollowSymLinks
            AllowOverride All
            Require all granted
        </Directory>
    
        ErrorLog ${APACHE_LOG_DIR}/mysite1_error.log
        CustomLog ${APACHE_LOG_DIR}/mysite1_access.log combined
    </VirtualHost>
    
  2. 禁用默认 VirtualHost 并启用创建的 VirtualHost:

    sudo a2dissite 000-default.conf
    sudo a2ensite mysite1.conf
    
  3. 重新加载 apache 服务:

    sudo service apache2 reload
    

关于Linux Apache 配置 - 您无权访问/在此服务器上?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35761795/

相关文章:

bash - "bash -c"与 "dash -c"

linux - 显示两个主机名的终端

linux - 在 Linux 上中止阻塞读取

linux - Bash:如何将一行插入文件中的特定位置?

apache - .htaccess指令以*不*重​​定向某些URL

php - 在 Mint 上设置 apache 和 php

apache - 在虚拟主机上访问 nominatim 时出现 403 错误

linux - 从 1 个 ec2 实例 rsync 到另一个实例

python - 在python中加载动画

python - 意外删除后如何在 ubuntu 中恢复 python 2.7[弄乱了我的/usr/bin/]