在Linode上configuration基于名称的虚拟主机?

我正在学习为apache 2configuration基于名称的虚拟主机。

现在,我的域名http://mydomain.com指向/var/www/index.html。 我希望它指向我新创build的/srv/www/mydomain.com/public_html/index.html。

我目前有两个文件:

  • 在/ etc / apache2的/网站可用/默认
  • /etc/apache2/sites-available/mydomain.com

这是他们的样子:

在/ etc / apache2的/网站可用/默认

NameVirtualHost myipaddr:80 <VirtualHost myipaddr:80> ServerAdmin webmaster@localhost DocumentRoot /var/www <Directory /> Options FollowSymLinks AllowOverride None </Directory> <Directory /var/www/> Options Indexes FollowSymLinks MultiViews AllowOverride None Order allow,deny allow from all </Directory> ## other default directives </VirtualHost> 

/etc/apache2/sites-available/mydomain.com

 <VirtualHost *:80> ServerAdmin [email protected] ServerName mydomain.com ServerAlias www.mydomain.com DocumentRoot /srv/www/mydomain.com/public_html/ ErrorLog /srv/www/mydomain.com/logs/error.log CustomLog /srv/www/mydomain.com/logs/access.log combined </VirtualHost> 

我执行了a2ensite mydomain.com并重新启动apache,但http://mydomain.com仍然指向默认的/ var / www /目录。 我猜apache不注册我的/etc/apache2/sites-available/mydomain.com文件?

我错过了configuration和安装中的一个步骤吗?

我不确定这是否是问题,但是首先要说明的是,您在NameVirtualHost设置中使用IP,而在mydomain.com中使用通配符。 您可能应该为NameVirtualHost和默认的虚拟主机使用通配符。

  • 你应该为“默认”设置一个不同的名字

ServerName不是www.mydomain.com

  • 您也可以将所有NameVirtualHost和VirtualHost设置为*:80,仅用于configuration的统一