VirtualHost with wildcard VirtualDocumentRoot

二次信任 提交于 2019-11-28 17:39:34

I use them :) You forgot about switching off canonical names - unfortunately I don't know why there must be ServerAlias in my configuration - it just won't work without it - code below is tested and working

<Directory "C:/LocalServer/*/public">
    Options Indexes FollowSymLinks
    AllowOverride All
    Order allow,deny
    Allow from all
    Require local
</Directory>

<VirtualHost *:80>
    # Apache will form URLs using the hostname supplied by the client
    UseCanonicalName Off

    # available aliases to use
    ServerAlias *.lab *.lab2

    # where to put them
    VirtualDocumentRoot "C:/LocalServer/%2/%1/public/"
</VirtualHost>

Given that you are obviously using windows for development, but (presumably) deploying to linux for production, have you thought about using a virtual machine for development?

I've written a guide for setting up here: http://otaqui.com/blog/1652/setting-up-a-virtualbox-virtual-machine-for-web-development-with-multiple-sites-using-mod_vhost_alias-and-virtualdocumentroot/ but in essence:

  • Share a directory (e.g. C:\VirtualWWW) from the HOST to the GUEST
  • Mount that share as /var/www in the GUEST, with www-data as the owner
  • Setup vhost_alias and VirtualDocumentRoot to map subdirectories in C:\VirtualWWW to virtual host subdomains, i.e. C:\VirtualWWW\project1 is mapped to http://project1.vhost/

Setting up new projects is then as simple as creating a new directory on your host, and the virtual machine guest uses that. If you are deploying to linux, you might save yourself all sorts of headaches (filename case-sensitivity being only one).

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!