1 TITLE: Apache with a Dynamic IP
3 AUTHOR: Ian Chilton <ian@ichilton.co.uk>
6 How to get Apache virtual hosting working when you have a dynamic IP,
11 This document explains how to use Apache's virtual hosting when you have a
12 dynamic IP address such as a dialup account, ADSL or a cable modem.
14 I copied /usr/local/apache/conf/httpd.conf to
15 /usr/local/apache/conf/httpd.conf.template and added this to the bottom:
17 (Do NOT replace the "----REPLACE_THIS_WITH_DYNIP----" bits, they are
18 supposed to be typed in like that :)
21 ------------ [SNIP httpd.conf.template ] ------------
24 NameVirtualHost ----REPLACE_THIS_WITH_DYNIP----
26 <VirtualHost ----REPLACE_THIS_WITH_DYNIP---->
27 ServerName www.domain1.com
28 DocumentRoot "/wwwroot/domain1"
29 ErrorLog /var/log/http-domain1-error_log
30 CustomLog /var/log/http-domain1-access_log common
33 <VirtualHost ----REPLACE_THIS_WITH_DYNIP---->
34 ServerName www.domain2.com
35 DocumentRoot "/wwwroot/domain2"
36 ErrorLog /var/log/http-domain2-error_log
37 CustomLog /var/log/http-domain2-access_log common
41 ------------ [SNIP httpd.conf.template ] ------------
44 Then, the clever bit..
46 If you running from /etc/ppp/ip-up, use:
48 cat /usr/apache/conf/httpd.conf.template |
49 sed -e "s/----REPLACE_THIS_WITH_DYNIP----/$4/g" >
50 /usr/apache/conf/httpd.conf
52 /usr/local/apache/bin/apachectl restart
57 MYIP=$(/sbin/ifconfig|grep -1 ppp0|cut -s -d ' ' -f12|
58 grep addr|cut -d ':' -f2)
60 cat /usr/apache/conf/httpd.conf.template |
61 sed -e "s/----REPLACE_THIS_WITH_DYNIP----/$MYIP/g" >
62 /usr/apache/conf/httpd.conf
64 /usr/local/apache/bin/apachectl restart
67 And that should be it !!
69 Just remember that in the future any changes you need to make are
70 made to httpd.conf.template, not httpd.conf and after changes
71 you need to run the sed statement which creates the httpd.conf.
72 (perhaps create a little script to do it for you).