当我输入 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/