dimo414 Posted April 19, 2007 Report Share Posted April 19, 2007 I have the following in my httpd.conf file:NameVirtualHost * ##### ROOT <VirtualHost *> ServerAdmin michael@digitalgemstones.com DocumentRoot /www/ ServerName localhost ErrorLog logs/root-error_log CustomLog logs/root-access_log common </VirtualHost> ##### GEMDEV <VirtualHost *> ServerAdmin michael@digitalgemstones.com DocumentRoot /www/dev/gemdev ServerName gemdev.localhost ErrorLog logs/gemdev-error_log CustomLog logs/gemdev-access_log common </VirtualHost> This seems to be right, since I can change the document root and still be directed to /www/. However when I try to access gemdev.localhost the browser responds server not found. I'm assuming this has something to do with where subdomains of localhost are directed to, but I don't know how to change that. Any help? Quote Link to comment Share on other sites More sharing options...
Ric Posted April 19, 2007 Report Share Posted April 19, 2007 The above looks correct, I assume you enter http://gemdev.localhost into your browser address bar. Your browser attempts to resolve this address by first looking in the hosts file hence you need an entry in this file that points to local host address 127.0.0.1 Looks something like this: 127.0.0.1 localhost # loop back address 127.0.0.1 gemdev.localhost # loop back address Your browser just needs the numeric address (127.0.0.1) with this information it sends a page request to your local server with the domain part (gemdev.com) in the header. Apache looks at this header information and directs to the appropriate top-level folder. The hosts file can be found in: c:\windows\~system32\drivers\etc — [Windows Vista] c:\windows\hosts — [Windows 95/98/me] c:\winnt\system32\drivers\etc\hosts — [Windows NT/2000/XP Pro] c:\windows\system32\drivers\etc\hosts — [Windows XP Home] Additional Information: What is more interesting if you like to use say www. gemdev.localhost Add this to the hosts file as well: 127.0.0.1 localhost # loop back address 127.0.0.1 gemdev.localhost # loop back address 127.0.0.1 www.gemdev.localhost # loop back address You also need a corresponding entry in the httpd.conf file: ##### GEMDEV <VirtualHost *> ServerAdmin michael@digitalgemstones.com DocumentRoot /www/dev/gemdev ServerName www.gemdev.localhost ErrorLog logs/gemdev-error_log CustomLog logs/gemdev-access_log common </VirtualHost> Now typing either of the following into your browser will take you to the same location. http://gemdev.localhostorhttp://www.gemdev.localhost You can use this technique for any number of Apache virtual hosts. Note: If you design on your local machine and publish your site/sites to a service provider you can use real domain names, just put these into the host file allowing your browser to resolve them and point to your local server. With your site published remember to remove the corresponding entries in your host file otherwise you will not be able to view your real live site on-line Sorry for the ramble but this is on my do list for UniCenter and will be added to the following page when I have time: http://center.uniformserver.com/new_users_...rs_hosts_1.html Quote Link to comment Share on other sites More sharing options...
dimo414 Posted April 19, 2007 Author Report Share Posted April 19, 2007 Your browser attempts to resolve this address by first looking in the hosts file hence you need an entry in this file that points to local host address 127.0.0.1 Hmm, is there any way to work with subdomains, or in some way split segments of the server into separate locations without using the hosts file? I can not use the hosts file, since I develop on many computers. Quote Link to comment Share on other sites More sharing options...
Ric Posted April 19, 2007 Report Share Posted April 19, 2007 That’s an interesting one, if your sites use relative links and you are not really bothered with what’s displayed in your browser address bar you can use an alias For example say you have two sites, site2 and site3 (located in folder www) they are complete and independent with their own index page. You would for test purposes access these using the following: http://localhost/site2/http://localhost/site3/ Those lines represent your real top-level domain names. Such as www.site2.com or www.site3.net when you publish that’s what you would use and see. However in a test situation you would see http://localhost/site2/ and http://localhost/site3/ respectively. If you are happy with that set the aliases as follows: Open the file httpd.confLocated in:*:\UniServer3_3\Uniform Server\diskw\usr\local\apache2\conf Search for this section: Alias /apanel/ "/home/admin/www/" <Directory "/home/admin/www/"> Options Indexes Includes AllowOverride All Order allow,deny Allow from all </Directory> Below this add the following: Alias /site2/ "/www/site2/" <Directory "/www/site2/"> Options Indexes FollowSymLinks MultiViews ExecCGI AllowOverride All Order allow,deny Allow from all </Directory> Alias /site3/ "/www/site3/" <Directory "/www/site3/"> Options Indexes FollowSymLinks MultiViews ExecCGI AllowOverride All Order allow,deny Allow from all </Directory> Note: You do not need the virtual host section at the bottom of the page for a test server. That may help! :angry: I can not use the hosts file, since I develop on many computers. I am not sure on that one Quote Link to comment Share on other sites More sharing options...
dimo414 Posted April 20, 2007 Author Report Share Posted April 20, 2007 Thanks, I'll give that a try! Out of curiosity, do you know any way to modify the DNS information for localhost like CNAME info (especially if you can do it via uniform server rather than the hosts file)? Quote Link to comment Share on other sites More sharing options...
dimo414 Posted April 20, 2007 Author Report Share Posted April 20, 2007 Ok, so the reason I wanted subdomains was so that all my relative URLs in differnet projects would work. All my developmental projects are in /diskw/www/dev/PROJECTNAME. This works, but unless I want to go in and edit all the URLs, or use absolute URLs, I have to change the documentroot to point to the right project folder, and then I can only work on one project until I restart the server. Can I set it so urls in these aliases point to the right location? IE <a href="/myFile.php"> should point to localhost/PROJECTNAME/myFile.php. Basically, I want to be able to develop multiple projects, without having to constantly change the documentroot, and without having to change all the URLs once it's uploaded to a live server. Quote Link to comment Share on other sites More sharing options...
Ric Posted April 21, 2007 Report Share Posted April 21, 2007 With those last two questions I now have three to answer! The alias solution works fine for relative links however it will fall over with root relative links. The CNAME cannot be resolved within Apache its only possible using a DNS server or local DNS like the host file. Looking at the original problem I think your use of NameVirtualHost sections in Apache is the correct way to precede. Since this is a test environment you can do what you like. I am thinking treat UniServer as a proxy and let the browser take the strain and become effectively your DNS server. I will take a look at this over the weekend it involves using a PAC (Proxy Auto-Configuration) file for your browser. Quote Link to comment Share on other sites More sharing options...
Ric Posted April 22, 2007 Report Share Posted April 22, 2007 Done http://center.uniformserver.com/virtual_ho...host_pac_1.html Hope it is of some help Quote Link to comment Share on other sites More sharing options...
dimo414 Posted April 26, 2007 Author Report Share Posted April 26, 2007 Thank you very much, that is exactly what I'm looking for! In the meantime, while I was away from the internet but not my computer, I wrote a pair of batch files to automatically insert my own HOSTS file upon calling server_start.bat and revert to the original HOSTS file upon calling stop.bat. I'll put the code on the wiki once I've perfected it, and made sure it works on several other computers, but your method also works! Though admittedly, if you're working with separate computers, you often won't have access to the same browser, and therefore will have to configure the browser every time as well. Nevertheless, thanks very much for all your input! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.