Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    Senior Coder
    Join Date
    Mar 2003
    Location
    Atlanta
    Posts
    1,037
    Thanks
    14
    Thanked 30 Times in 28 Posts

    Apache Virtual Hosts for Many Different Sites

    I was just wondering how everyone else handles their server when creating a new web site (locally).

    I've just been creating a new Virtual hosts and modifying my HOSTS file with every new site. Surely there must be a more efficient way to do this.
    Most of my questions/posts are fairly straightforward and simple. I post long verbose messages in an attempt to be thorough.

  • #2
    Senior Coder CFMaBiSmAd's Avatar
    Join Date
    Oct 2006
    Location
    Denver, Colorado USA
    Posts
    3,011
    Thanks
    2
    Thanked 312 Times in 304 Posts
    If you were managing a live server, you would be using a Hosting Control Panel and the HOSTS file information would be adding entries to an actual name server instead. You might try to find out if any of the opensource/free hosting control panels support using a HOSTS file, otherwise, you probably need to write a script to do this yourself.
    If you are learning PHP, developing PHP code, or debugging PHP code, do yourself a favor and check your web server log for errors and/or turn on full PHP error reporting in php.ini or in a .htaccess file to get PHP to help you.

  • #3
    Regular Coder
    Join Date
    Oct 2004
    Posts
    356
    Thanks
    0
    Thanked 16 Times in 16 Posts
    I use a PAC file
    Code:
    function FindProxyForURL(url, host)
    {
    	if(isPlainHostName(host)
    	  || dnsDomainIs(host, '.internal'))
    	{
    		return 'PROXY 127.0.0.1:80; DIRECT';
    	}
    	else
    	{
    		return 'DIRECT';
    	}
    }
    Any host name without a dot (PlainHostName) or any .internal domain name will be sent to 127.0.0.1:80.


    And mod_vhost_alias
    Code:
    # Catch all.
    # http://example/ to /path/example/
    # http://example.com/ to /path/example.com/
    <VirtualHost *:80>
    	ServerName          _default_
    
    	DocumentRoot        /path/
    	VirtualDocumentRoot /path/%0
    </VirtualHost>
    
    # For .internal
    # http://example.internal to /different/example/
    <VirtualHost *:80>
    	ServerName          a.internal
    	ServerAlias         *.internal
    
    	DocumentRoot        /different/
    	VirtualDocumentRoot /different/%-2+
    </VirtualHost>
    
    # A "normal" document root for example.org.
    <VirtualHost *:80>
    	ServerName          example.org
    	ServerAlias         *.example.org
    
    	DocumentRoot        /another/example.org
    </VirtualHost>
    A problem with VirtualDocumentRoots is that it does not change the DOCUMENT_ROOT variable.

  • Users who have thanked schleppel for this post:

    StupidRalph (01-05-2009)

  • #4
    Senior Coder
    Join Date
    Mar 2003
    Location
    Atlanta
    Posts
    1,037
    Thanks
    14
    Thanked 30 Times in 28 Posts
    Been away on holiday....

    But I chose to use dynamic virtual hosts. But I plan on looking at the above suggestions thanks.

    http://httpd.apache.org/docs/2.0/vhosts/mass.html
    Most of my questions/posts are fairly straightforward and simple. I post long verbose messages in an attempt to be thorough.

  • #5
    Regular Coder
    Join Date
    Oct 2004
    Posts
    356
    Thanks
    0
    Thanked 16 Times in 16 Posts
    But I chose to use dynamic virtual hosts.
    That's the same as what i was suggesting (the second part).

    The PAC file part is a replacement for editing the HOSTS file each time to add a new "domain".

  • #6
    Senior Coder
    Join Date
    Mar 2003
    Location
    Atlanta
    Posts
    1,037
    Thanks
    14
    Thanked 30 Times in 28 Posts
    Sorry, I did notice that after I posted. Thanks for your help for pointing me in the right direction with the PAC file.
    Most of my questions/posts are fairly straightforward and simple. I post long verbose messages in an attempt to be thorough.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •