我一直试图为我的网站配置虚拟服务器,但没有任何成功。我在 VPS 上运行 Debian 2.6.32。我已经为虚拟服务器配置了许多配置,并且将其留得相对简单以进行测试(我只启用了 epicbackroads.com)。以下是我的三个虚拟主机:
<VirtualHost *:80>
DocumentRoot "/srv/www/epicbackroads.com/public_html"
ServerName epicbackroads.com
<Directory "/srv/www/epicbackroads.com/public_html">
allow from all
Options +Indexes
</Directory>
</VirtualHost>
<VirtualHost *:80>
ServerAdmin [email protected]
ServerName johnpwarren.com
DocumentRoot /srv/www/domain2.com/public_html
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
<Directory /srv/www/domain2.com/public_html/>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all
</Directory>
ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
<Directory "/usr/lib/cgi-bin">
AllowOverride None
Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
Order allow,deny
Allow from all
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel warn
CustomLog ${APACHE_LOG_DIR}/access.log combined
这是我的 /etc/hosts 文件:
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
127.0.0.1 localhost.localdomain localhost
# Auto-generated hostname. Please do not remove this comment.
208.84.135.70 serv1.epicbackroads.com serv1
208.84.135.70 epicbackroads.com epicbackroads
208.84.135.70 johnpwarren.com johnpwarren
208.84.135.70 voip.johnpwarren.com voip.johnpwarren
::1 localhost ip6-localhost ip6-loopback
和 /etc/resolv.conf:
search epicbackroads.com
nameserver 8.8.8.8
nameserver 8.8.4.4
以及卷曲检查:
# curl -I epicbackroads.com
HTTP/1.1 200 OK
Date: Mon, 27 May 2013 09:16:40 GMT
Server: Apache/2.2.16 (Debian)
Last-Modified: Mon, 27 May 2013 05:05:00 GMT
ETag: "32237e0-4f-4ddac173588f2"
Accept-Ranges: bytes
Content-Length: 79
Vary: Accept-Encoding
Content-Type: text/html
X-Pad: avoid browser bug
</VirtualHost>
但是,浏览器仍然显示“无法找到服务器”错误。我还应该检查什么?
更新:此外,我运行了 telnet 并收到了此信息:
telnet 208.84.135.70 80
Trying 208.84.135.70...
Connected to 208.84.135.70.
Escape character is '^]'.
Connection closed by foreign host.
答案1
您发布的 Apache 配置不完整或完全无效。
第二个虚拟主机有语法错误(缺少“<”)
VirtualHost *:80>
并且它永远不会关闭。缺失:
</VirtualHost>
此外,您还缺少ServerName
每个虚拟主机。
https://httpd.apache.org/docs/current/mod/core.html#servername
Apache 不知道要服务哪个虚拟主机,并且将默认使用配置中的第一个。
除此之外,epicbackroads.com 的问题似乎出在您的 DNS 配置上。epicbackroads.com 无法解析任何 IP 地址。
您的服务器可以解析该域名,因为您已在 /etc/hosts 文件上手动配置了它,但您的 PC 无法解析该域名,因此不会加载任何内容。