Linux
1 IP 上基於多個名稱的虛擬伺服器的 Apache2 配置
我一直在嘗試為我的網站配置虛擬伺服器,但沒有任何運氣。我在 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 admin@domain2.com 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.
您發布的 Apache 配置不完整或完全無效。
第二個虛擬主機有語法錯誤(缺少’<’)
VirtualHost *:80>
它永遠不會關閉。失踪:
</VirtualHost>
ServerName
每個虛擬主機上 也缺少您。https://httpd.apache.org/docs/current/mod/core.html#servernameApache 將不知道要為哪個虛擬主機提供服務,並將預設為配置中的第一個。
除此之外,epicbackroads.com 的問題似乎是您的 DNS 配置。epicbackroads.com 無法解析到任何 IP 地址。
您的伺服器可以解析域,因為您已在 /etc/hosts 文件中手動配置它,但您的 PC 無法解析此域,因此它不會載入任何內容。