Can someone tell if I can create VirtualHosts on my testserver? I access the testserver by the usual 'http://localhost'.
If i can, how do I do it?
/Grodan :)
I know how to create virtual hosts when I have different IP:s or a DNS. But in this case I only have 'localhost'.
Can I create VirtualHosts on my testserver?
/Grodan :)
/Grodan :)
I'll try to have different portnumbers and se what happens... :)
/Grodan :)
Now you can navigate to the virtual server by name, just as if you had a DNS entry.
I can then use name-based virtual hosts?
/Grodan :)
As in PsychoTekk's example the port is not required. The requests are all served on port 80. The host can be named whatever you want, and have as many hosts as you have defined in Apache. eg. www1.example.com, www.another-example.com then your host file would look like this:
127.0.0.1 localhost
127.0.0.1 www1.example.com
127.0.0.1 www.another-example.com
The only caution is to stay away from real registered domain names, because your hosts file takes precedence over DNS resolution, i.e. if you used www.yahoo.com as one of your host names and put it in your hosts file then you could never get to the real www.yahoo.com because it would resolve to 127.0.0.1 and your local Apache would try to serve content for that host.
(edited by: Air at 5:49 pm (utc) on Mar. 10, 2002)
Host-file:
127.0.0.1 localhost
127.0.0.1 wwwhkr.localhost
127.0.0.1 test.localhost
httpd.conf:
NameVirtualHost *
<VirtualHost *>
DocumentRoot "C:/Program Files/Apache Group/Apache/htdocs"
ServerName localhost
</VirtualHost>
<VirtualHost *>
DocumentRoot "C:/Program Files/Apache Group/Apache/htdocs/wwwhkr3"
ServerName wwwhkr.localhost
</VirtualHost>
<VirtualHost *>
DocumentRoot "C:/Program Files/Apache Group/Apache/htdocs/test"
ServerName test.localhost
</VirtualHost>
[localhost...] woks fine but none of the others... ?
/Grodan
/Grodan
Also DNS is a pain .. if I need another test server its quicker just to listen on a different port.
Listen 80
Listen 81
Listen (etc)
<VirtualHost *:80>
DocumentRoot "C:/Webfiles/host1/"
ServerName localhost
</VirtualHost>
<VirtualHost *:81>
DocumentRoot "C:/Webfiles/host2/"
ServerName localhost
</VirtualHost>
Just restart apache and voila.
HTH
<VirtualHost *:81>
ServerName localhost2
</VirtualHost>
the virtual host works fine while the default wort doesn't work anymore :(
Air & PsychoTekk: It works fine now. The problem was that in my '.htaccess'-file I had an old path that didn't work with the new VirtualHost:s. Sorry my error again :(
Thx everyone for your answers :D
/Grodan :)
You did put in the
listen portnum
And only NameVirtualHost * once?
In the main section of the httpd.conf file? Search for "Listen 80" and just add a couple of extra lines. It tells apache to use the extra ports as well - obviously don't choose a port that is used by something else. Works just fine on my apache on WinNT ... 80,81,82,83 etc.
Apache 1.3.23.
[erm sorry reread the post ;)]
[added]
You need to set up a virtual host for every port that you wish to use - including port 80 ;)
<VirtualHost *:80>
blah blah
</VirtualHost>
[/added]