linux - 解析虚拟主机 apache 2

标签 linux apache virtualhost

当我输入 test1.example.com test2.example.com 等地址时,我正在尝试设置我的 apache 服务器来访问某些文件夹。

到目前为止,我阅读并做了很多事情,但还没有成功。如果您能帮助我,我将非常感激。

首先,我使用 ubuntu 12.10 作为我的桌面,并在那里设置了 apache 服务器。我已在解析为 127.0.0.1 的主机中添加了 example.com。到目前为止没有问题。我已在 apache 中启用 vhost_alias 和 mod_rewrite,并将其用于我的虚拟服务器

NameVirtualHost *:80
UseCanonicalName Off
<VirtualHost *:80>
   ServerName example.com
   ServerAlias *.example.com

   RewriteEngine On

   RewriteCond %{HTTP_HOST} !^(www\.)?([^\.]+).example.com$
   RewriteRule ^(.*) $1 [F]

   VirtualDocumentRoot /home/example/server/projects/%1/public_html

     <Directory />
                Options FollowSymLinks
                AllowOverride all
        </Directory>
        <Directory /home/radoslav/server/projects>
                Options Indexes FollowSymLinks MultiViews
                AllowOverride all
                Order allow,deny
                allow from all
        </Directory>

   #log file for this server
   CustomLog /var/log/apache2/example.com.log combined
</VirtualHost>

但是当我打开 test.example.com 时,它说浏览器可以找到 test.example.com,无论我在指定的路径中有这个目录。只是为了澄清一下,apache 有权限读取这个目录,所以它不是这个。当我从控制台 ping example.com 时,我得到 ping,但如果我 ping test.example.com,我得到错误,找不到主机。正如您所看到的,无论我是否正确设置了所有内容,它都无法解析地址。

大家有什么帮助吗?

最佳答案

您需要在主机文件中添加 test.example.com 以及要使用的任何其他主机名。主机文件不支持通配符。

关于linux - 解析虚拟主机 apache 2,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16249014/

相关文章:

linux - Ubuntu 上 Eclipse CDT 的 32/64 位问题

linux - ZONE_HIGHMEM 在 32 位 x86 内核地址空间中的映射

linux - iRedMail NginX 配置文件更新

linux - 配置 symfony 和 apache

dynamic - 如何在nginx中设置海量动态虚拟主机?

linux - 为什么 gdb 会挂起?

c++ - 将相同数据写入两个文件的有效方法

PHP session 超时为 0,但 session 仍将过期

缺少 Java org.apache.poi.unsupportedfileformaexception

macos - 如何让虚拟主机在 OS X Lion 中工作?