apache上的虚拟主机,URL类似于子文件夹

Jib*_*bla 13 apache ubuntu apache2 ubuntu-server vhosts

我感兴趣的是,如果我可以在域名上使用apache的vhosts: http://something.com/somethinghttp:// {server-ip-address-here}/something

我在Ubuntu服务器上使用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>
    
    Run Code Online (Sandbox Code Playgroud)

  3. 在/ etc/apache2/sites-enabled /中创建了符号链接,它指向/ etc/apache2/sites-available/demo

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

现在我得到的是,当我去{my-domain}时,我去了我创建的vhost,但问题是服务器在任何情况下指向我,不仅是{my-domain}/demo我想要的.

总之,我希望我可以创建不同的虚拟主机并将它们连接到具有相同base-url的不同URL,例如www.mydomain.com/vhost1,www.mydomain.com/vhost2等.

可能吗?谢谢 :)

jef*_*g07 16

首先,它出现的原因是任何情况都是因为你的虚拟主机有*:80设置,所以如果没有匹配请求它使用第一个虚拟主机条目

如果我理解你要做什么,看起来你可能只想为每个'虚拟主机'添加别名

你要做的不是虚拟主机(至少虚拟主机应该做什么),但你可以通过使用apache的别名功能来实现它

Alias /vhost1 /whatever/folder/your/vhost1/site/is/at
Alias /vhost2 /whatever/folder/your/vhost2/site/is/at
Run Code Online (Sandbox Code Playgroud)

所以现在你使用的域名,例如http://whatever.com/vhost1http://whatever.com/vhost2 这两个em将显示为单独的站点

  • 嘿伙计们,你究竟想把它放在线上? (2认同)