apache默认的虚拟主机configuration为www域名

这是我的虚拟主机的Apache默认configuration

<VirtualHost *:80> ServerAdmin webmaster@localhost DocumentRoot /var/www <Directory /> Options +FollowSymLinks AllowOverride None </Directory> <Directory "/var/www/mydir"> AllowOverride FileInfo Limit Options Indexes </Directory> <Directory /var/www/> 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 

这适用于http://mydomain.com,但不适用于http://www.mydomain.com如何用www服务我的域名?

这个问题只适用于默认的域名,我的其他域名可以同时使用这个configuration文件

 <VirtualHost *:80> ServerName otherdomain.com ServerAlias www.otherdomain.com ServerAdmin webmaster@localhost DocumentRoot /var/www/otherdomain ServerSignature Off <Directory /> Options +FollowSymLinks AllowOverride None </Directory> <Directory /var/www/otherdomain> Options Indexes +FollowSymLinks MultiViews AllowOverride all Order allow,deny allow from all </Directory> # Possible values include: debug, info, notice, warn, error, crit, # alert, emerg. LogLevel warn CustomLog /var/log/apache2/otherdomain.com_access.log combined ErrorLog /var/log/apache2/otherdomain.com_error.log </VirtualHost> 

您必须使用ServerNameServerAlias参数告诉Apache每个虚拟主机的服务器名称。

喜欢:

 <Virtualhost *:80> ServerName mydomain.com ServerAlias www.mydomain.com whatever.mydomain.com ... </Virtualhost> 

如果你得到的回应是“服务器没有find”,那么我打赌你的DNS设置有问题。 不幸的是,既然你已经select隐藏真实的域名,这里的任何人都不可能帮你弄清楚可能是什么。 但是,这里有一个简单的方法来validation是DNS还是Apacheconfiguration,这是问题

首先,在您正在浏览的同一台机器上执行nslookup www.yourdomain.com 。 你得到一个IP的回报? 如果是的话,那是你所期望的吗?

其次,不要使用浏览器到服务器,而是使用telnet直接与之通话。 喜欢这个:

 [jenny@jennys:~]$ telnet your.server.ip.here 80 Trying your.server.ip.here... Connected to your.server.name (your.server.ip.here). Escape character is '^]'. GET / HTTP/1.1 Host: www.yourdomainname.com 

input您的域名后,请务必按两次Enter键。 然后在这里发布输出。