apache上的虚拟主机与URL等子文件夹
-
14-11-2019 - |
题
我感兴趣,如果我可以在apache上使用域名vhosts: http://something.com/something 或 http:// {server-ip-address-here} / something ?
我在Ubuntu服务器上使用Apache 2.2.20,那是我的家庭服务器和我在这里测试一些东西,我没有任何DNS服务器,我只有公共IP地址和附加的域名打开DNS服务。
所以,我做了什么:
-
我在 / etc / apache2 /站点中创建了新的文件“演示” - 可用
-
我放在那里(实际上它是从默认文件中复制的修改):
<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>
-
在/ etc / apache2 /站点中创建了symlink /启用/哪个点到/ etc / apache2 / sites可用/演示
-
创建 /vhosts/demo/index.html 文件。
现在我得到的是,当我去{my-domain}我去了我创建的vhost,但问题是服务器在任何情况下都指向我,不仅{my-domain} / demo什么我想要。
总之,我希望我可以创建不同的虚拟主机,并将它们附加到不同的URL,其将具有相同的基础URL,例如www.mydomain.com/vhost1,www.mydomain.com/vhost2等。< / p>
是可能的吗? 谢谢:)
解决方案
To start, the reason why it goes there is ANY case is cause you have you have a *:80 setting for your virtual host, so if nothing matches the request it uses the first virtual host entry
If I understand what you are trying to do it appears like you might just want to alias each 'virtual host'
What you are trying to do isn't quite a virtual host (at least what a virtual host is supposed to do), but you might be able to accomplish it by using alias feature of apache
Alias /vhost1 /whatever/folder/your/vhost1/site/is/at
Alias /vhost2 /whatever/folder/your/vhost2/site/is/at
So now whatever domain you use e.g. http://whatever.com/vhost1 or http://whatever.com/vhost2 The both of em will appear as separate sites