在本地主机上设置子域名

我一直试图在我的本地开发环境dev.localhost上设置一个子域。 我使用Ubuntu 11.10和Apache2。 到目前为止,我已经编辑我的主机文件,包括行127.0.0.1 dev.localhost 。 我在/etc/apache2/sites-available中创build了一个名为axis的文件,如下所示:

 <VirtualHost *:80> DocumentRoot /var/www/Axis/trunk ServerName dev.localhost ServerAlias *.localhost <Directory /var/www/Axis/trunk/> Options Indexes FollowSymLinks MultiViews +Includes AllowOverride None Order allow,deny allow from all </Directory> </VirtualHost> 

然后,我使用sudo a2ensite axis启用该网站。 我遇到了一个无主机命名错误,并将行ServerName localhost主机添加到我的default文件sites-available 。 我也遇到了一个与NameVirtualHost的错误,我通过将NameVirtualHost *:80添加到httpd.conf并在ports.conf注释掉它。

现在,当我导航到dev.localhost我得到了相同的网页,如果我导航到localhost 。 换句话说, localhostdev.localhost指向/var/www但我想dev.localhost指向/var/www/Axis/trunk

任何想法我要去哪里错了? 谢谢

编辑:从apache2ctl -S输出

 ulimit: 88: error setting limit (Operation not permitted) VirtualHost configuration: wildcard NameVirtualHosts and _default_ servers: *:80 is a NameVirtualHost default server localhost (/etc/apache2/sites-enabled/000-default:1) port 80 namevhost localhost (/etc/apache2/sites-enabled/000-default:1) port 80 namevhost dev.localhost (/etc/apache2/sites-enabled/axis:1) Syntax OK 

您需要设置您的/etc/hostsC:\Windows\system32\drivers\etc\hosts (以pipe理员身份)以反映“子域”。 因此,将127.0.0.1 dev.localhost添加到任一文件(取决于您的平台)。

然而,可能“域名”在域名parsing方面有点特殊,因为它可能不能作为域名。 所以相反,你可以把类似mylan.local服务器名称和dev.mylan.local作为子域名。 (你基本上可以使用你想要的一切)

最后,不要忘记重新加载Apache的apache2ctl restart因为它需要重新加载其configuration。