Rob*_*t K 5 virtualhost apache-2.2
我将 Linode 配置为带有 Apache 2.2.14 的 Ubuntu 10.04.2 Web 服务器。
我总共有 4 个站点,都定义/etc/apache2/sites-available为虚拟主机。所有站点几乎都是相同的配置克隆。除了我上次的所有网站都成功运行。
default: (www.)exampleadnetwork.com
(www.)example.com
reseller.example.com
trouble: client1.example.com
Run Code Online (Sandbox Code Playgroud)
当我访问该client1.example.com网站时,我不断收到此页面:
有用!
这是该服务器的默认网页。
Web 服务器软件正在运行,但尚未添加任何内容。
在我的ports.conf文件中,我将 NameVirtualHost 正确设置为端口 80 上的 IP 地址。
如果我访问“www.sub.example.com”别名,网站就可以工作了!如果我在没有 www 的情况下访问它,我会看到上面发布的“It Works”摘录。甚至apache2ctl -S显示我的 vhost 文件解析正确并添加到混合中。
我的vhost配置文件如下:
<VirtualHost 127.0.0.1:80>
ServerAdmin webmaster@example.com
ServerName client1.example.com
ServerAlias client1.example.com www.client1.example.com
DocumentRoot /srv/www/client1.example.com/public_html/
ErrorLog /srv/www/client1.example.com/logs/error.log
CustomLog /srv/www/client1.example.com/logs/access.log combined
<directory /srv/www/client1.example.com/public_html/>
Options -Indexes FollowSymLinks
AllowOverride None
Order allow,deny
Allow from all
</directory>
</VirtualHost>
Run Code Online (Sandbox Code Playgroud)
其他网站是以下网站的变体:
<VirtualHost 127.0.0.1:80>
ServerAdmin webmaster@example.com
ServerName example.com
ServerAlias example.com www.example.com
DocumentRoot /srv/www/example.com/public_html/
ErrorLog /srv/www/example.com/logs/error.log
CustomLog /srv/www/example.com/logs/access.log combined
</VirtualHost>
Run Code Online (Sandbox Code Playgroud)
唯一不同的站点是另一个子域:
<VirtualHost 127.0.0.1:80>
ServerAdmin webmaster@example.com
ServerName reseller.example.com
ServerAlias reseller.example.com
DocumentRoot /srv/www/reseller.example.com/public_html/
ErrorLog /srv/www/reseller.example.com/logs/error.log
CustomLog /srv/www/reseller.example.com/logs/access.log combined
</VirtualHost>
Run Code Online (Sandbox Code Playgroud)
文件名是不带 www 的 FQDN。字首。
我已遵循此建议,但仍然无法正确访问子域。
请尝试在 ServerName 和 ServerAlias 中不要有重复条目。
例如:
<VirtualHost *:80>
ServerAdmin webmaster@example.com
ServerName sub.example.com
ServerAlias www.sub.example.com
DocumentRoot /srv/www/sub.example.com/public_html/
ErrorLog /srv/www/sub.example.com/logs/error.log
CustomLog /srv/www/sub.example.com/logs/access.log combined
<directory /srv/www/sub.example.com/public_html/>
Options -Indexes FollowSymLinks
AllowOverride None
Order allow,deny
Allow from all
</directory>
Run Code Online (Sandbox Code Playgroud)