了解虚拟主机设置

好,所以我有一个服务器,我想把几个应用程序,我有虚拟主机configuration问题。 这是我有什么,我想要什么我做错了一些方向…好,所以第一个文件是/etc/apache2/ports.conf

NameVirtualHost 184.106.111.142:80 Listen 80 <IfModule mod_ssl.c> Listen 443 </IfModule> <IfModule mod_gnutls.c> Listen 443 </IfModule> 

那么我有/etc/apache2/sites-available/somesite.com

 <VirtualHost 184.106.111.142:80> ServerAdmin [email protected] ServerName somesite.com ServerAlias www.somesite.com DocumentRoot /srv/www/somesite.com/ ErrorLog /srv/www/somesite.com/logs/error.log CustomLog /srv/www/somesite.com/logs/access.log combined <Directory "/srv/www/somesite.com/"> AllowOverride all Options -MultiViews </Directory> </VirtualHost> 

当我访问somesite.com一切都很好,但是当我添加另一个虚拟主机,并可以说这就是那个叫anothersite.com。 所以我有/etc/apache2/sites-available/anothersite.com

 <VirtualHost 184.106.111.142:80> ServerAdmin [email protected] ServerName anothersite.com ServerAlias www.anothersite.com DocumentRoot /srv/www/anothersite.com/ ErrorLog /srv/www/anothersite.com/logs/error.log CustomLog /srv/www/anothersite.com/logs/access.log combined <Directory "/srv/www/anothersite.com/"> AllowOverride all Options -MultiViews </Directory> </VirtualHost> 

然后我运行以下命令

 >> sudo a2ensite anothersite.com Enabling site anothersite.com. Run '/etc/init.d/apache2 reload' to activate new configuration! >> /etc/init.d/apache2 reload * Reloading web server config apache2 ...done. 

但是当我访问anothersite.com或somesite.com时,他们都失败了。与虚拟主机有什么关系。 它可能是与IP或什么的NameVirtualHost声明…也许我对vhost设置的理解不清楚。 我不明白的是为什么现在这两个网站突然不工作了。我会高度赞赏清晰度

顺便说一句,anothersite.com或somesite.com是我改变的唯一的东西,使其更具可读性

我testing你的configuration和所有的工作。 使用apache2 -S进行debugging:

 # . /etc/apache2/envvars && apache2 -S VirtualHost configuration: 184.106.111.142:80 is a NameVirtualHost default server somesite.com (/etc/apache2/sites-enabled/somesite.com:1) port 80 namevhost somesite.com (/etc/apache2/sites-enabled/somesite.com:1) port 80 namevhost anothersite.com (/etc/apache2/sites-enabled/anothersite.com:1) Syntax OK 

然后在浏览器或CURL中打开网站(wget不要设置主机头):

 # curl somesite.com a # curl anothersite.com b