<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <HTML> <HEAD> <META http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <META NAME="GENERATOR" CONTENT="lfparser_2.8"> <META NAME="LFCATEGORY" CONTENT="System Administration"> <TITLE>lf129, System Administration: Recycling Ip Addresses with Apache</TITLE> <!-- stylesheet added by lfparser: --> <style type="text/css"> <!-- pre { font-familiy:monospace,Courier } --> </style> </HEAD> <BODY bgcolor="#ffffff" text="#000000"> <!-- this is generated html code. NEVER use this file for your translation work. Instead get the file with the same article number and .meta.shtml in its name. Translate this meta file and then use lfparser program to generate the final article --> <!-- lfparser can be obtained from http://main.linuxfocus.org/~guido/dev/lfparser.html --> <!-- 2pdaIgnoreStart --> <MAP name="top"> <AREA shape="rect" coords="367,9,418,30" alt="Home" href="../index.shtml"> <AREA shape="rect" coords="423,9,457,30" alt="Map" href="../map.html"> <AREA shape="rect" coords="463,9,508,30" alt="Index" href="../indice.html"> <AREA shape="rect" coords="514,9,558,30" alt="Search" href="../Search/index.html"> </MAP> <MAP name="bottom"> <AREA shape="rect" coords="78,0,163,15" alt="News" href="../News/index.html"> <AREA shape="rect" coords="189,0,284,15" alt="Archives" href="../Archives/index.html"> <AREA shape="rect" coords="319,0,395,15" alt="Links" href="../Links/index.html"> <AREA shape="rect" coords="436,0,523,15" alt="About LF" href="../aboutus.html"> </MAP> <!-- IMAGE HEADER --> <CENTER> <IMG src="../../common/images/Topbar-en.gif" width="600" height="40" border="0" alt="[Top bar]" ismap usemap="#top" ><BR> <IMG src="../../common/images/Bottombar-en.gif" width="600" height="21" border="0" alt="[Bottom bar]" ismap usemap="#bottom"> </CENTER> <!-- SSI_INFO --> <!-- tr_staticssi include virtual --> <!-- tr_staticssi exec cmd --> <!-- addedByLfdynahead ver 1.4 --><TABLE ALIGN="right" border=0><TR><TD ALIGN="right"><FONT SIZE="-1" FACE="Arial,Helvetica">This document is available in: <A href="../../English/January2000/article129.shtml">English</a> <A href="../../Castellano/January2000/article129.html">Castellano</a> <A href="../../Deutsch/January2000/article129.shtml">Deutsch</a> <A href="../../Francais/January2000/article129.shtml">Francais</a> <A href="../../Italiano/January2000/article129.html">Italiano</a> <A href="../../Nederlands/January2000/article129.shtml">Nederlands</a> <A href="../../Turkce/January2000/article129.shtml">Turkce</a> <A href="../../Korean/January2000/article129.html">Korean</a> </FONT></TD></TR></TABLE><br> <!-- 2pdaIgnoreStop --> <!-- SHORT BIO ABOUT THE AUTHOR --> <TABLE ALIGN=LEFT BORDER=0 hspace=4 vspace=4 WIDTH="30%" > <TR> <TD> <!-- 2pdaIgnoreStart --> <!-- PALM DOC --> <TABLE BORDER=0 hspace=4 vspace=4> <TR> <TD> <font size=1> <img src="../../common/images/2doc.gif" width=34 align=left border=0 height=22 alt="convert to palm"><a href="http://cgi.linuxfocus.org/cgi-bin/2ztxt">Convert to GutenPalm</a><br>or <a href="http://cgi.linuxfocus.org/cgi-bin/2pda">to PalmDoc</a></font> </TD> </TR> </TABLE> <!-- END PALM DOC --> <!-- 2pdaIgnoreStop --> <br> <IMG SRC="../../common/images/Atif-Ghaffar.jpg" ALT="[Photo of the Author]" HEIGHT=100 WIDTH=100> <BR>by <A HREF="mailto:aghaffar@developer.ch">Atif Ghaffar</A> <BR><BR> <I>About the author:</I><BR> <P> I live and work in Switzerland as a webmaster/unix administrator. My passions include, Linux, unix, Perl, Apache and GPL softwares. More about me can be found on my <a href="http://www.developer.ch/~aghaffar">homepage</a><br></P> <BR><i>Content</i>: <UL> <LI><A HREF="#lfindex0">Why should we recycle IP addresses?</A></LI> <LI><A HREF="#lfindex1">How to recycle ip adresses?</A></LI> <LI><A HREF="#lfindex2">Using wildcards, dynamic hostnames</A></LI> <LI><A HREF="#lfindex3">My virtual hosts configuration file</A></LI> <LI><A HREF="#lfindex4">Additional Resources</A></LI> <LI><A HREF="http://cgi.linuxfocus.org/cgi-bin/lftalkback?anum=129&lang=en">Talkback form for this article</A></LI> </UL> </TD></TR></TABLE> <!-- HEAD OF THE ARTICLE --> <H2>Recycling Ip Addresses with Apache</H2> <IMG SRC="../../common/images/illustration129.gif" ALT="[Illustration]" HSPACE=10 HEIGHT=133 WIDTH=360> <!-- ABSTRACT OF THE ARTICLE --> <P><i>Abstract</i>: <P> This article demonstrates how to serve multiple virtual webservers using the same ip address with Apache on Unix/Linux. The article assumes that the reader has some knowledge of Apache and DNS and unix. <br> The target audience of this article is ISPs, System Administrator and anyone who cares to read and learn. </P> <HR size="2" noshade align="right"><BR> <!-- BODY OF THE ARTICLE --> <A NAME="lfindex0"> </A> <H2>Why should we recycle IP addresses?</H2> <p> Ip address recycling is useful for number of reasons. <ol> <li>one can easily run out of ip addresses <li>one might have only one ip address (as in my case) <li>More system administrators time to add interfaces to host to use multiple ip addresses. </ol> <A NAME="lfindex1"> </A> <H2>How to recycle ip adresses?</H2> Using Apache it is simple to serve multiple domains with a single ip address.<br> For this article we will assume the ip address to be 192.168.1.1, and hostname hometranet.home. <br> Simply add a line like this to your httpd.conf file<br> <xmp> NameVirtualHost 192.168.1.1:80 </xmp> <br> <i>Next we will add three virtual servers using the same ip address</i> <br> <pre> #Host for unix files <VirtualHost 192.168.1.1:80> ServerName unix.hometranet.home DocumentRoot /www/unix/html ScriptAlias /cgi-bin/ /www/unix/cgi-bin/ TransferLog /www/unix/logs/access_log ErrorLog /www/unix/logs/error_log </VirtualHost> #Host for perl stuff <VirtualHost 192.168.1.1:80> ServerName perl.hometranet.home DocumentRoot /www/perl/html ScriptAlias /cgi-bin/ /www/perl/cgi-bin/ TransferLog /www/perl/logs/access_log ErrorLog /www/perl/logs/error_log </VirtualHost> #Here we host some cool Apache stuff <VirtualHost 192.168.1.1:80> ServerName apache.hometranet.home DocumentRoot /www/apache/html ScriptAlias /cgi-bin/ /www/apache/cgi-bin/ TransferLog /www/apache/logs/access_log ErrorLog /www/apache/logs/error_log </VirtualHost> </pre> <i> So using one ip address we have easily managed 3 different virtualhosts.<br> <br> Next add CNAMES or A Records for these names in your nameserver's <br> zone file and dont forget to increment the serial number :)<br> for eg: in my /var/named/hometranet.home.fwd, I would add<br> </i> <xmp> perl.hometranet.home. IN A 192.168.1.1 apache.hometranet.home. IN A 192.168.1.1 unix.hometranet.home. IN A 192.168.1.1 </xmp> <br> Please note: If you call this host by any other name than the ones given in the virtual config then the first virtual host will respond. <br> Before Apache 1.3.x the last one would have had responded. <br> For eg: If this host is named madmag then calling http://madmag.hometranet.home will give you the same result as calling unix.hometranet.home. <br> <A NAME="lfindex2"> </A> <H2>Using wildcards, dynamic hostnames</H2> <p> This is the cool part. Apache allows wildcards to be used in hostanames. <br> Meaning you can set a domain *.home.hometranet.home and all queries to user1.home.hometranet.home, user2.home.hometranet.home, user3.home.hometranet.home,etc will be responded. <br> Example: <br> <pre> #host for users <VirtualHost 192.168.1.1:80> ServerName home.hometranet.home ServerAlias *.home.hometranet.home DocumentRoot /www/home/html TransferLog /www/home/logs/access_log ErrorLog /www/home/logs/error_log </VirtualHost> and an entry in the named zone file. *.home.hometranet.home. IN A 192.168.1.1 </pre> Note: This trick will not work if you are using Microsoft DNS Server. Apparently it refuses to accept wildcards in hostnames. <br> (But you arent using one, are you??) <br> I once wrote a small system that allows users on the network to add their CV in the database, and using the above trick, their CVs were availabe by http://theirUserName.cv.developer.ch. </p> <A NAME="lfindex3"> </A> <H2><a href="../../common/src/article129/vhosts.conf.txt">My virtual hosts configuration file</a></H2> <p> <a href="../../common/src/article129/vhosts.conf.txt">Here</a> is a bit more exhaustive configuration file that i have separated from my main httpd.conf file<br> This one is actually on my server.<br> <br>To include this file in the main httpd.conf you can use the <b>Include</b> directive in your main httpd.conf. <br>Include "/etc/vhosts.conf" </p> <A NAME="lfindex4"> </A> <H2>Additional Resources</H2> <dl> <dt> [Apache name-based Virtual Host Support] <dd> <a href="http://www.apache.org/docs/vhosts/name-based.html">http://www.apache.org/docs/vhosts/name-based.html</a> <dt> [Apache Virtual Host documentation] <dd> <a href="http://www.apache.org/docs/vhosts/index.html">http://www.apache.org/docs/vhosts/index.html</a> <dt>[An In-Depth Discussion of Virtual Host Matching] <dd> <a href="http://www.apache.org/docs/vhosts/details.html">http://www.apache.org/docs/vhosts/details.html</a> </dl> <!-- vim: set sw=2 ts=2 et: --> <!-- 2pdaIgnoreStart --> <A NAME="talkback"> </a> <h2>Talkback form for this article</h2> Every article has its own talkback page. On this page you can submit a comment or look at comments from other readers: <center> <table border="0" CELLSPACING="2" CELLPADDING="1"> <tr BGCOLOR="#C2C2C2"><td align=center> <table border="3" CELLSPACING="2" CELLPADDING="1"> <tr BGCOLOR="#C2C2C2"><td align=center> <A href="http://cgi.linuxfocus.org/cgi-bin/lftalkback?anum=129&lang=en"><b> talkback page </b></a> </td></tr></table> </td></tr></table> </center> <HR size="2" noshade> <!-- ARTICLE FOOT --> <CENTER><TABLE WIDTH="95%"> <TR><TD ALIGN=CENTER BGCOLOR="#9999AA"> <A HREF="../../common/lfteam.html">Webpages maintained by the LinuxFocus Editor team</A> <BR><FONT COLOR="#FFFFFF">© Atif Ghaffar, <a href="../../common/copy.html">FDL</a> <BR><a href="http://www.linuxfocus.org">LinuxFocus.org</a></FONT> <BR><a href="http://cgi.linuxfocus.org/cgi-bin/lfcomment?lang=en&article=article129.shtml" target="_TOP">Click here to report a fault or send a comment to LinuxFocus</A><BR></TD> <!-- OLD FORMAT, NO TRANSLATION INFO --> </TR></TABLE></CENTER> <p><font size=1>2001-01-27, generated by lfparser version 2.8</font></p> <!-- 2pdaIgnoreStop --> </BODY> </HTML>