2012-02-29 68 views
12

我感兴趣,如果我能有像域名在Apache虚拟主机: http://something.com/something的http:// {服务器IP -address-here} /东西虚拟主机与URL的子文件夹一样

我在Ubuntu服务器上使用Apache 2.2.20,这是我的家庭服务器,我在这里测试一些东西,我没有任何DNS服务器在这里,我拥有的只是公共IP地址和附加到它的域名从开放的DNS服务。

所以,我做了什么:

  1. 我在的/ etc/apache2的/网站可用
  2. 创建新的文件“演示”我把有这个(实际上它被复制与从默认文件修改):

    <VirtualHost *:80> 
        ServerAdmin [email protected] 
        ServerName {mydomain-here}/demo/ 
        DocumentRoot /vhosts/demo 
    <Directory /> 
         Options FollowSymLinks 
         AllowOverride None 
    </Directory> 
    <Directory /vhosts/demo/> 
         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 
    
    Alias /doc/ "/usr/share/doc/" 
    <Directory "/usr/share/doc/"> 
        Options Indexes MultiViews FollowSymLinks 
        AllowOverride None 
        Order deny,allow 
        Deny from all 
        Allow from 127.0.0.0/255.0.0.0 ::1/128 
    </Directory> 
    </VirtualHost> 
    

  3. 创建符号链接在/ etc/apache2的/启用的站点 - /指向到/ etc/apache2的/网站可用/演示

  4. 创建/vhosts/demo/index.html文件。

而现在我所得到的是,当我去{我的域}我去VHOST我所创建的,但问题是,服务器在任何情况下,有指向我,不仅{我的域} /演示我想要的。

总而言之,我希望我可以创建不同的虚拟主机,并将它们附加到具有相同基本URL的不同网址,例如www.mydomain.com/vhost1,www.mydomain.com/vhost2等。

可能吗? 谢谢:)

回答

15

要开始了,为什么它会出现任何情况的原因是因为你有你有一个*:80设置你的虚拟主机,因此如果没有匹配请求它使用的第一个虚拟主机条目

如果我理解你正在做什么它看起来就像你可能只是想互为别名“虚拟主机”

你所要做的是不太虚拟主机(至少是虚拟主机应该这样做),但你可以通过使用apache的别名功能来完成它

Alias /vhost1 /whatever/folder/your/vhost1/site/is/at 
Alias /vhost2 /whatever/folder/your/vhost2/site/is/at 

因此,无论您使用哪个域名,例如http://whatever.com/vhost1http://whatever.com/vhost2 这两个em将显示为单独的网站

+0

谢谢:)我创建了别名,我得到了确切的结果,我想! 但是,为了感兴趣: 看起来它不可能以这种方式制作虚拟主机,是吗? – Jibla 2012-02-29 20:45:56

+0

我不这么认为,我从来没有像以前那样使用过它。通常,当您需要一台服务器时,可以使用它来为多个域/ ips例如www.vhost1.com和www.vhost2.com并使用虚拟主机是服务器如何知道服务器www.vhost1.com和www.vhost2的文件。com – jeffchong07 2012-02-29 20:53:07

+0

在你的情况,只有一个域,所以虚拟主机不一定有用区分你的网站 – jeffchong07 2012-02-29 20:54:52