Adding Virtual Hosts to Ubuntu Apache Posted on February 28, 2009<http://brucewampler.wordpress.com/2009/02/28/adding-virtual-hosts-to-ubuntu-apache/> by brucewampler <http://brucewampler.wordpress.com/author/brucewampler/>
Now that I have Ubuntu installed and the Apache server working, I need to configure some Virtual Hosts. I have several names registered at dyndns.comthat all point to the same IP. Right after you get Apache going, it defaults to serving from a default location, in this case /var/www. Any http requests coming into the box are all routed to that directory. But Apache can support multiple virtual hosts. So if I route say example1.dnsalias.com and example2.dynalias.com to my IP via dyndns.com, I want them to be each served from their own directory. The default /var/wwwhas system ownership and would need to be changed. So I'm going to create a directory for each site under my user directory. So I'll create /home/bruce/sites/example1 and /home/bruce/sites/example2 to host the files for each site. Now we need to make Apache use them. In the default configuration, Apache is already set up to support multiple virtual Hosts. In order to get the new sites working, we need to create a couple of configuration files in the /etc/apache2/sites-available directory, then enable them, and then restart Apache. If you look in the sites-available, you'll find a file called default. This represents the default Apache serving configuration. Copy this file twice to serve as a basis for the new configuration files. sudo cp default example1and sudo cp default example2. You need to make two or three changes to *each* of these files, and add one line. There's a line in the file tagged ServerAdmin. If you want, you can make the value a real e-mail address. There are also two lines labeled Document Root and another in a %lt;Directory> statementthat have the path to the directory being served - in this case, it should be /var/www/. Change both of those to the directory that will contain the new site files - /home/bruce/sites/example1/ and again with example2. Almost done. Now after the ServerAdmin line add a new line: ServerName example1.dynalias.com and again with example2 file. Use whatever actual domain names you've registered with dyndns.com or other dynamic name server you're using. So now in addition to the */etc/apache2/sites-available/default* file, you'll have two more files - example1 and example2, which have been modified to point to the actual hosting directories, and with the appropriate domain names. Now we have to tell Apache to serve the new domains. Ubuntu has a couple of convenience commands to enable and disable sites. So, to enable the new sites, enter sudo a2ensite example1 and again sudo a2ensite example2. These commands copy the configuration files you created into the /etc/apache2/sites-enabled directory. We're almost there. Finally, you have to restart Apache2 so that it reconfigures to serve the new sites. Simply enter sudo /etc/init.d/apache2 reload. Be sure there's an index.html file with some content in each of the /home/username/sites/example1 and example2 directories. Now if you enter http://example1.dnsalias.com to a browser, you should see the contents of the appropriate file. I hope I've made these steps pretty clear. It really isn't that hard. 1. Create directories to host the content of a new virtual site. 2. Make a copy of the /etc/apache2/sites-available/defaults file with a site appropriate name. 3. Change the two /var/www/ entries to the actual directory of the new site. 4. Add the ServerName line with the real domain name you will be hosting. 5. Use a2ensite to enable the new site, and finally reload Apache2 so it knows about the new site One point to add though - after making all these changes you will *need to add example1.com to /etc/hosts.conf* 2011/3/29 Alexandros Georgopoulos <alexander_...@hotmail.com> > > παμε στην επομενη ερωτηση τωρα.... :P :P > πως μπορω να κανω το test.dyndns.org να ανοιγει τον φακελο test και να μην > διαβαζει το κεντρικο /www/ > > > Date: Tue, 29 Mar 2011 15:12:51 +0300 > > From: platsa...@gmail.com > > To: ubuntu-gr@lists.ubuntu.com > > Subject: Re: erwthseis gia server > > > > Ας ελπισουμε οτι δεν ειναι production το μηχανημα :) > > On 03/29/2011 03:03 PM, Alexandros Georgopoulos wrote: > > > δούλεψε!! :) ναι κατι γινοταν με το σκριπτ λογικά. τασβησα ολα, ξανα > ανεβασα τα αρχεια εδωσα permissions στα αρχεια που ζητουσε το σκριπτ κ > δουλεψε κανονικα. :) > > > > > > σασ ευχαριστω παρα πολυ όλους για την υποστιριξη παιδια και σιγουρα > κατι θα προκυψει πάλι.... :P :) > > > > > > -- > > Ubuntu-gr mailing list > > Ubuntu-gr@lists.ubuntu.com > > > > If you do not want to receive any more messages from the ubuntu-gr > mailing list, please follow this link and choose unsubscribe: > > https://lists.ubuntu.com/mailman/listinfo/ubuntu-gr > > -------------- next part -------------- > An HTML attachment was scrubbed... > URL: < > https://lists.ubuntu.com/archives/ubuntu-gr/attachments/20110329/1115bfee/attachment.html > > > -- > Ubuntu-gr mailing list > Ubuntu-gr@lists.ubuntu.com > > If you do not want to receive any more messages from the ubuntu-gr mailing > list, please follow this link and choose unsubscribe: > https://lists.ubuntu.com/mailman/listinfo/ubuntu-gr > -- Παναγιώτης Θεοδωρόπουλος Panagiotis Theodoropoulos <tpanagio...@gmail.com> -------------- next part -------------- An HTML attachment was scrubbed... URL: <https://lists.ubuntu.com/archives/ubuntu-gr/attachments/20110329/96d848c0/attachment.html> -- Ubuntu-gr mailing list Ubuntu-gr@lists.ubuntu.com If you do not want to receive any more messages from the ubuntu-gr mailing list, please follow this link and choose unsubscribe: https://lists.ubuntu.com/mailman/listinfo/ubuntu-gr