Using a directory in VirtualHost ServerName

2019-01-21 14:55发布

问题:

I'm currently using name-based virtual host configuration, to server about 5 different websites from the same IP address, just like in the apache documentation:

<VirtualHost *:80>
ServerName www.domain.tld
DocumentRoot /www/domain
</VirtualHost>

<VirtualHost *:80>
ServerName www.otherdomain.tld
DocumentRoot /www/otherdomain
</VirtualHost>

Is it possbile to have something like:

<VirtualHost *:80>
ServerName www.domain.tld/folderpath
DocumentRoot /www/software
</VirtualHost>

The webpages in this folder are using a different software stack, and I'd like to keep it nicely separate. I tried the method above but it didn't work.

回答1:

It's not possible the way you show - a VirtualHost is always just a host. But you could use an Alias.

<VirtualHost *:80>
ServerName www.domain.tld
DocumentRoot /www/domain

Alias /folderpath /www/software

</VirtualHost>


回答2:

Is it possible to have a different vhost for each application like that:

<VirtualHost *:80>
ServerName www.domain.tld
DocumentRoot /www/domain
</VirtualHost>

<VirtualHost *:80>
ServerName www.domain.tld
Alias otherApp /www/otherApp
</VirtualHost>