VirtualHost with wildcard VirtualDocumentRoot

后端 未结 2 550
余生分开走
余生分开走 2020-12-23 18:23

I\'m trying to create a fallback for my virtual hosts. My configuration looks like this:

# Fetch all pre-defined hosts
         


        
相关标签:
2条回答
  • 2020-12-23 18:27

    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>
    
    0 讨论(0)
  • 2020-12-23 18:47

    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).

    0 讨论(0)
提交回复
热议问题