VirtualHosts for multiple sites using HOSTS file
Posted by: dannyh (---.vf.shawcable.net)
Date: January 09, 2007 11:12PM

I develop websites and use WAMP as my testing server. it resides on the same computer that I do my development on.

I don't want to register with any DNS server etc.

I read that you can run multiple websites in Apache by editing the hosts file in Windows and adding virtualhosts to httpd.conf

Here is my hosts file:

127.0.0.1 localhost
127.0.0.1 test1
127.0.0.1 test2
127.0.0.1 test3

Here is the bottom of my httpd.conf file:

NameVirtualHost *:80

<VirtualHost *>
ServerName localhost
DocumentRoot "C:/wamp/www"
</VirtualHost>

<VirtualHost *>
ServerName test1
DocumentRoot "C:/wamp/www/mollio"
</VirtualHost>

etc.

So, in theory I should be taken to the "C:/wamp/www/mollio" directory if I access [test1] from the same computer that the server is on.

However, it shows me this directory instead: "C:/wamp/www"

If I move the test1 virtualhost above the localhost virtualhost in the httpd.conf file, that directory is displayed instead. It is displayed no matter what address I use, [localhost] or [test1]

Why isn't this working?

Options: ReplyQuote
Re: VirtualHosts for multiple sites using HOSTS file
Posted by: yfastud (---.cable.mindspring.com)
Date: January 09, 2007 11:58PM

Did you restart wamp after modified?

Have fun

[www.jlbn.com] (testing web server)
[test.jlbn.com] (testing codes)
[forum.jlbn.com] (testing phpBB2)
[forums.jlbn.com] (testing phpBB3)
[mail.jlbn.com] (testing mailserver)
[ftp.jlbn.com] (testing ftp server)
[www.jlbn.com] (testing flashes)
[www.jlbn.com] (testing images)
[joomla.jlbn.com] (testing Joomla 1.0.10)
[fusion.jlbn.com] (testing phpFusion 6.01.6)
[nuke.jlbn.com] (testing phpNuke 7.9)
[nukep.jlbn.com] (testing phpNuke Platinum 7.6.b.4v2)
[pnuke.jlbn.com] (testing PostNuke 0.800-MS2)
[nukevo.jlbn.com] (testing phpNuke Evolution 2.0.1)

Options: ReplyQuote
Re: VirtualHosts for multiple sites using HOSTS file
Posted by: dannyh (---.vf.shawcable.net)
Date: January 10, 2007 12:12AM

Yes I did restart, of course.

I figured it out by reading another article.

config file:

NameVirtualHost 127.0.0.1

<VirtualHost 127.0.0.1>
ServerName localhost
DocumentRoot c:/wamp/www
ErrorLog c:/wamp/apache2/logs/error.log
TransferLog c:/wamp/apache2/logs/access.log
ScriptAlias /cgi-bin/ c:/wamp/apache2/cgi-bin/
</VirtualHost>

<VirtualHost 127.0.0.1>
ServerName project1
DocumentRoot c:/wamp/www/__MY_PROJECTS__/project1
</VirtualHost>

Hosts file:

127.0.0.1 localhost
127.0.0.1 project1

For some reason, this works like a charm.

Options: ReplyQuote
Re: VirtualHosts for multiple sites using HOSTS file
Posted by: yfastud (---.cable.mindspring.com)
Date: January 10, 2007 02:19AM

Quote


<VirtualHost *>
ServerName localhost
DocumentRoot "C:/wamp/www"
</VirtualHost>

<VirtualHost *>
ServerName test1
DocumentRoot "C:/wamp/www/mollio"
</VirtualHost>

Look back your setup and compare w/ mine, it seems missing port 80 in <VirtualHost *>

NameVirtualHost *:80

<VirtualHost *:80>
ServerName test.jlbn.com
ServerAlias test
DocumentRoot "C:/wamp/www/test"
</VirtualHost>

Host file:
127.0.0.1 test

And I can access it online as [test.jlbn.com] or offline as [test]

Have fun

[www.jlbn.com] (testing web server)
[test.jlbn.com] (testing codes)
[forum.jlbn.com] (testing phpBB2)
[forums.jlbn.com] (testing phpBB3)
[mail.jlbn.com] (testing mailserver)
[ftp.jlbn.com] (testing ftp server)
[www.jlbn.com] (testing flashes)
[www.jlbn.com] (testing images)
[joomla.jlbn.com] (testing Joomla 1.0.10)
[fusion.jlbn.com] (testing phpFusion 6.01.6)
[nuke.jlbn.com] (testing phpNuke 7.9)
[nukep.jlbn.com] (testing phpNuke Platinum 7.6.b.4v2)
[pnuke.jlbn.com] (testing PostNuke 0.800-MS2)
[nukevo.jlbn.com] (testing phpNuke Evolution 2.0.1)



Post Edited (01-10-07 02:20)

Have fun,

FREE One A Day
FREE Photo
FREE Games
FREE Websites
FREE Portable GPS
FREE WAMP Guides

Options: ReplyQuote


Sorry, only registered users may post in this forum.