<?xml version="1.0" encoding="UTF-8"?> <rss
version="2.0"
xmlns:content="http://purl.org/rss/1.0/modules/content/"
xmlns:wfw="http://wellformedweb.org/CommentAPI/"
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:atom="http://www.w3.org/2005/Atom"
xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
> <channel><title>gHacks Technology News &#124; Latest Tech News, Software And Tutorials &#187; virtual hosts</title> <atom:link href="http://www.ghacks.net/tag/virtual-hosts/feed/" rel="self" type="application/rss+xml" /><link>http://www.ghacks.net</link> <description>A technology news blog covering software, mobile phones, gadgets, security, the Internet and other relevant areas.</description> <lastBuildDate>Sat, 11 Feb 2012 21:54:04 +0000</lastBuildDate> <language>en</language> <sy:updatePeriod>hourly</sy:updatePeriod> <sy:updateFrequency>1</sy:updateFrequency> <generator>http://wordpress.org/?v=3.3.1</generator> <atom:link rel="hub" href="http://pubsubhubbub.appspot.com"/><atom:link rel="hub" href="http://superfeedr.com/hubbub"/> <item><title>Adding a Name-Based Virtual Host in Apache</title><link>http://www.ghacks.net/2009/03/17/adding-a-name-based-virtual-host-in-apache/</link> <comments>http://www.ghacks.net/2009/03/17/adding-a-name-based-virtual-host-in-apache/#comments</comments> <pubDate>Tue, 17 Mar 2009 15:27:52 +0000</pubDate> <dc:creator>Jack Wallen</dc:creator> <category><![CDATA[Advice]]></category> <category><![CDATA[Linux]]></category> <category><![CDATA[Open Source]]></category> <category><![CDATA[The Web]]></category> <category><![CDATA[Tutorials Advanced]]></category> <category><![CDATA[Web Development]]></category> <category><![CDATA[apache]]></category> <category><![CDATA[Fedora]]></category> <category><![CDATA[ubuntu]]></category> <category><![CDATA[virtual hosts]]></category> <guid
isPermaLink="false">http://www.ghacks.net/?p=11288</guid> <description><![CDATA[If you are an Apache user for the hosting of either internal or external web sites then you know how flexible this web server can be. But did you know you can host more than one site on that server? You can thanks to Virtual sites. You can host virtual sites based on either IP [...]]]></description> <content:encoded><![CDATA[<p>If you are an Apache user for the hosting of either internal or external web sites then you know how flexible this web server can be. But did you know you can host more than one site on that server? You can thanks to Virtual sites. You can host virtual sites based on either IP address or Name. If IP addresses are in short supply the best choice, of course, is name-based virtual hosting.</p><p>In this article I will show you how to add name-based virtual hosts in your Apache web server. This will require you to edit the <strong>/etc/httpd/conf/httpd.conf</strong> file so be prepared for some command-line action. NOTE: This file can be located in various locations</p><p><span
id="more-11288"></span></p><p>If you&#8217;ve never edited your <strong>httpd.conf</strong> file don&#8217;t worry, it&#8217;s not that difficult. Just make sure you use good comments so you know what you did and where you did it. Otherwise your virtual host section could get lost in the other sections.</p><p>The section of Apache where your virtual hosts will go is called, aptly, Virtual Hosts. The format of an entry looks like this:</p><p><code>&lt;VirtualHost *:80&gt;<br
/> ServerAdmin admin@dummy-host.example.com<br
/> DocumentRoot /www/docs/dummy-host.example.com<br
/> ServerName dummy-host.example.com<br
/> ErrorLog logs/dummy-host.example.com-error_log<br
/> CustomLog logs/dummy-host.example.com-access_log common<br
/> &lt;/VirtualHost&gt;</code></p><p>Before you actually start configuring your virtual host you need to make sure you have the NameVirtualHosts line uncommented out. The line will look like:</p><p>NameVirtualHosts *</p><p>You can find the line by using the <em>grep </em>command like so:</p><p><em>grep -n NameVirtualHosts /etc/httpd/conf/httpd.conf</em></p><p>(NOTE: Edit the path to your httpd.conf file to reflect your setup.)</p><p>The <em>grep</em> command will return to you which line the NameVirtualHost entry is on. Now open up the Nano editor and scroll down a bit. You can hit the key combination Ctrl-c to find out what line you are on. Once you find the line you will remove the &#8220;#&#8221; character (no quotes).</p><p>With that out of the way you are ready.</p><p>To illustrate how this is done I will show you how to create a virtual server for mail. The following assumes the doc root is <strong>/var/www/. </strong>Add the following entries to your <strong>httpd.conf</strong> file:</p><p><code>&lt;VirtualHost *:80&gt;<br
/> <span
class="indent"> DocumentRoot /www/yourcompany<br
/> ServerName www.yourcompany.com<br
/> # Other directives here<br
/> </span>&lt;/VirtualHost&gt;</code></p><p><code>&lt;VirtualHost *:80&gt;<br
/> <span
class="indent"> DocumentRoot /www/mail<br
/> ServerName mail.yourcompany.com<br
/> # Other directives here<br
/> </span>&lt;/VirtualHost&gt;</code></p><p>NOTE: Where <em>yourcompany.com</em> is the actual FQDN you use.</p><p>NOTE: If you need to change your port you can change it to suit your needs from the default port 80.</p><p>The above is the bare minimum configuration for your virtual servers. There are a LOT of possible directives you can use. For example, you might want to add error logging to these virtual hosts for debugging purposes. To add error logs to your virtual mail host? you would add the lines:</p><p><code>ErrorLog /var/log/httpd/mail-error_log common<br
/> CustomLog /var/log/httpd/mail-access_log common</code></p><p>To your mail virtual host entry (above the &lt;/VirtualHost&gt; line.)</p><p>Once you have these entries complete you will need to save the <strong>httpd.conf</strong> file and restart Apache. To restart Apache issue one of the following commands:</p><p><em>/etc/rc.d/ini</em>t.d/httpd restart</p><p>or</p><p><em>/etc/init.d/apache2 restart</em></p><p>You&#8217;re done. You should now be able to hit the new virtual hosts.</p><p><strong>Final Thoughts</strong></p><p>Creating virtual hosts is a quick way to expand the capabilities of your Apache server, cut costs, and save IP addreses. Have you ever deployed virtual hosts with Apache? If so, share your experiences.</p> ]]></content:encoded> <wfw:commentRss>http://www.ghacks.net/2009/03/17/adding-a-name-based-virtual-host-in-apache/feed/</wfw:commentRss> <slash:comments>4</slash:comments> </item> </channel> </rss>
