Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/linux/28.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Linux Apache配置-您不需要';您没有访问/访问此服务器的权限吗?_Linux_Apache_Ubuntu_Apache2 - Fatal编程技术网

Linux Apache配置-您不需要';您没有访问/访问此服务器的权限吗?

Linux Apache配置-您不需要';您没有访问/访问此服务器的权限吗?,linux,apache,ubuntu,apache2,Linux,Apache,Ubuntu,Apache2,如何告诉Apache将127.0.0.1指向一个特定的文件夹,如/var/www/projects/mysite1/ 我使用的是sudogedit/etc/apache2/apache2.conf,这是我的配置: <Directory /> Options FollowSymLinks AllowOverride all Require all denied </Directory> <Directory /usr/share>

如何告诉Apache将
127.0.0.1
指向一个特定的文件夹,如
/var/www/projects/mysite1/

我使用的是
sudogedit/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/
重新启动服务器后,在我的浏览器上出现以下错误:

禁止的

您没有访问/访问此服务器的权限

Apache/2.4.7(Ubuntu)服务器127.0.0.1端口80


你知道我该怎么做吗?

我认为实现这一目标的最佳方法是创建虚拟主机

  • /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>
    
  • 重新加载apache服务:

    sudo service apache2 reload
    

  • 非常感谢你的回答!
    sudo service apache2 reload