How can I set up multiple apache local web sites on Ubuntu?

I added the following to httpd.conf:

<VirtualHost *:80>
DocumentRoot "/wwwroot/htdocs/firstsite/"
ServerName www.vhostsite.com
</VirtualHost>

Now I try to go to www.vhostsite.com but browser says he can't find server.

Though, firstsite folder is created in htdocs, and it contains index.html (that is intended to show up in browser)

wwwroot is directory where apache is installed

link|improve this question
Your browser needs to know an IP address, so add the dummy www.vhostsite.com to your /etc/hosts file, like I wrote. – Arjan Feb 25 '10 at 11:28
Can't this be done without editing hosts file? – Emenims Feb 25 '10 at 11:41
1  
That would require a DNS server. Or registering a true domain, and mapping your server to your public IP address. (But even then some home routers require you to use the hosts file, for otherwise the browser cannot connect to that public IP address from within your own network.) – Arjan Feb 25 '10 at 12:02
@Arjan is right, if you want www.vhostsite.com to resolve to localhost you need hosts or DNS. if you run DD-WRT/OpenWRT on your home router you may be able to tweak it to add your own DNS settings there; hosts is easier tho. – quack quixote Feb 25 '10 at 12:35
feedback

2 Answers

Your browser needs to know an IP address, while the server then needs more details as for which site to serve. So, to host multiple sites on localhost you cannot serve all of them at http://localhost or http://127.0.0.1. Instead:

  • Use subfolders, like http://localhost/site1/

  • Or: set up dummy domains in your /etc/hosts file (name-based virtual hosting; the browser will connect to an IP address that is used for multiple sites, and then specify the requested host in the HTTP headers):

    127.0.0.1 www.vhostsite.com
  • Or: use multiple ports, like http://localhost:8080 and http://localhost:8081 (port-based virtual hosting)

link|improve this answer
feedback

you can use rapache to have a GUI to setup your domains instead of editing the config by hand.

link|improve this answer
feedback

Your Answer

 
or
required, but never shown