【问题标题】:Virtual hosts on apache with URL's like subfoldersapache 上的虚拟主机,带有 URL 之类的子文件夹
【发布时间】:2012-03-19 07:50:22
【问题描述】:

我感兴趣的是,我是否可以在 apache 上拥有具有以下域名的虚拟主机: http://something.com/somethinghttp://{server-ip-address-here}/something

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

那么,我做了什么:

  1. 我在 /etc/apache2/sites-available 中创建了新文件“demo”
  2. 我把它放在那里(实际上它是从默认文件修改复制的):

    <VirtualHost *:80>
       ServerAdmin webmaster@localhost
       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/sites-enabled/ 中创建了指向 /etc/apache2/sites-available/demo 的符号链接

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

现在我得到的是,当我转到 {my-domain} 时,我转到了我创建的虚拟主机,但问题是服务器在任何情况下都将我指向那里,而不仅仅是 {my-domain}/demo 什么我要。

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

有可能吗? 谢谢:)

【问题讨论】:

    标签: apache ubuntu apache2 vhosts ubuntu-server


    【解决方案1】:

    首先,它出现在任何情况下的原因是因为你有一个 *: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 两者都将显示为单独的站点

    【讨论】:

    • 谢谢 :) 我创建了别名,我得到了我想要的结果!但是,出于兴趣:看起来不可能那样制作虚拟主机,是吗?
    • 我不这么认为,我以前从来没有这样用过。通常,当您需要一台服务器能够为多个域/ips 提供文件时,您会使用它,例如www.vhost1.com 和 www.vhost2.com 和使用虚拟主机是服务器如何知道服务器 www.vhost1.com 和 www.vhost2.com 的文件
    • 在您的情况下,只有一个域,因此虚拟主机不一定有助于区分您的网站
    • 谢谢老兄 :) 我得到了我想要的别名 ;)
    • 嘿伙计们,你应该把上面的行放在哪里?
    猜你喜欢
    • 1970-01-01
    • 2011-03-25
    • 2013-10-04
    • 2015-01-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-07-05
    • 2017-03-22
    相关资源
    最近更新 更多