Fix Apache directory lists on dynamic IP sites

Nov 10, '02 06:10:57PM

Contributed by: jchi

Like many people I use a dynamic dns service for the webserver on my cable modem. Unfortunately I noticed that when accessing the web site from outside my LAN, only exact URLs generated a correct web page. For example http://mysite.dnsalias.com:8080/aa would get a error, but http://mysite.dnsalias.com:8080/aa/index.html would get the expected page. On my LAN, the results were the expected page, or if the page wasn't there a directory listing.

I finally traced the problem to the webserver returning a redirect to the browser to 172.16.1.2 (the LAN ip of my webserver) instead of the IP address of my router or the IP name from the dynamic DNS service. The internal IP address obviously doesn't work outside my LAN.

The fix is edit the apache config file at /etc/httpd/httpd.conf, and search for the section that contains:

# ServerName allows you to set a host name which is...
# your server if it's different than the one the...
# "www" instead of the host's real name).
Once you've found this section, add the line:
ServerName mysite.dnsalias.com
Replace mysite.dnsalias.com with the DNS name you have mapped to your webserver via the dynamic DNS service). Save and restart apache and your webserver should work as expected.

Comments (5)


Mac OS X Hints
http://hints.macworld.com/article.php?story=20021110151057778