在localhost上的Apache:给虚拟主机指定特定的服务器名称

我首先问我的问题,下面是我迄今试图解决的事情的细节:

本地主机上运行的Apache上,我想要有不同的虚拟主机,可以通过url访问: http://name-of-the-virtual-host.name-of-the-machine/

细节:

所以我有我的笔记本电脑的8080端口上运行的Apache。 Linux Mint,Debian发行版。 一切都在本地进行testing,所以不涉及DNS! 我使用的IP地址是127.0.1.1,它具有我的计算机的域,名为fabjoa。 在文件/etc/apache2/apache2.conf ,我已经把:

 ServerName fabjoa 

在文件/etc/hosts ,确实存在该行

 127.0.1.1 fabjoa 

在文件/etc/apache2/ports.conf

 NameVirtualHost *:8080 Listen 8080 

现在,我的虚拟主机的conf文件。 该文件被称为goyahkla,位于/etc/apache2/sites-available/ ,并在/etc/apache2/sites-enabled有一个符号链接。 在这个文件上,我有以下几点:

 <VirtualHost *:8080> ServerName goyakhla.fabjoa ServerAdmin webmaster@localhost DocumentRoot /var/sites/goyahkla .... <Directory /var/sites/goyahkla/> Options Indexes FollowSymLinks MultiViews AllowOverride All Order allow,deny allow from all </Directory> ... </VirtualHost> 

运行apache2ctl configtest给我语法OK。 现在,在浏览器上,打开http://fabjoa:8080/确实指向虚拟主机goyahkla(因为这是我唯一的),但没有findhttp://goyahkla.fabjoa:8080 。 其他debugging:

 telnet goyahkla.fabjoa:8080 telnet: could not resolve goyahkla.fabjoa:8080/telnet: Name or service not known lynx goyahkla.fabjoa:8080 Looking up 'goyahkla.fabjoa' first Looking up 'www.goyahkla.fabjoa.com', guessing... Looking up goyahkla.fabjoa first Looking up www.goyahkla.fabjoa.com, guessing... Looking up www.goyahkla.fabjoa.com:8080 Making HTTP connection to www.goyahkla.fabjoa.com:8080 Alert!: Unable to connect to remote host. lynx: Can't access startfile http://www.goyahkla.fabjoa.com:8080/ 

任何想法如何达到目的?

我必须在每个虚拟主机的/etc/hosts创build新条目。

例如,我已经添加了以下行:

 127.0.2.1 goyahkla 

这使我可以访问它

 http://goyahkla/ 

你正在寻找的是你的hosts文件中的127.0.1.1 *.fabjoa风格的语法。 不幸的是,hosts文件不支持这个。 您必须使用DNS,或者像上面提到的那样分别input每个DNS。