apache - 错误为属于同一域的文件夹设置 VirtualHost

标签 apache ubuntu apache2 vhosts mod-vhost-alias

Noob Here.. 我的 Ubuntu 机器上有以下文件夹结构

 /var/www/
        /folder1
        /folder2

现在我想将我的 url xyz.com 重定向到 folder1 和 xyz.com/blog 到 folder2。我正在使用以下 Vhost 配置文件

对于 xyz.com 到文件夹 1
  <VirtualHost *:80>
    ServerAdmin webmaster@localhost
    ServerName xyz.com
    ServerAlias www.xyz.com

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

对于 xyz.com/blog 到 folder2
   <VirtualHost *:80>
    ServerAdmin webmaster@localhost
    ServerName xyz.com/blog
    ServerAlias www.xyz.com/blog

    DocumentRoot /var/www/folder2
    <Directory />
            Options FollowSymLinks
            AllowOverride None
    </Directory>

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

当我在 url 中输入 xyz.com 时,它为我提供来自 folder1 的索引文件(如预期和正确)但是当我输入 xyz.com/blog 它显示 404:未找到错误
  Not Found

  The requested URL /blog/ was not found on this server.

  Apache/2.2.22 (Ubuntu) Server at socialcosmo.com Port 80

我已经花了几个小时在这上面,仍然无法找出问题:(
任何帮助将不胜感激

最佳答案

没有包含路径的主机(域名)之类的东西。 xyz.com/blog不是有效的 ServerName .

删除第二个虚拟主机并添加 alias directive给你的第一个。
Alias /blog /var/www/folder2

关于apache - 错误为属于同一域的文件夹设置 VirtualHost,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15914501/

相关文章:

python - 无法在 Ubuntu 中使用 yum 安装 python-pip ..已解决

mysql - 减少 Linux 服务器上磁盘 IO 的最佳方法

linux - 来自 iOS 的 OPTIONS 请求

Apache Bench POST : Is it possible to read from string or stdin, 而不是文件?

apache - 如何在服务器 Windows 中的 plesk17 上安装 Apache

regex - Apache Rewrite 子域上的图像

java - 当我尝试增加堆空间时,为什么 Java CLI 没有反应?

python - 将多条图形线平均为一条,python和matplotlib

.htaccess 重定向美化URL/隐藏结构

apache - 如何处理仅处理子域的 Rails 站点的 VirtualHost/Passenger 条目?