How to enable Zeroconf for Apache

Zeroconf is a great way for hosts and services to advertise themselves on the network. Unfortunately, Apache doesn’t provide support for advertising itself as an HTTP service out-of-the-box, so you’ll need to do some work to get it working.

There are two methods, the first use mod_dnssd which is good because it ties directly into Apache, so when Apache runs, it advertises, but when Apache is down (for whatever reason), then it stops advertising. It also means any changes you make to your Apache configuration (e.g. port) are automatically reflected in the advertisement.

The second method uses the built-in Zeroconf daemon in *nix called Avahi. Avahi is similar to Bonjour/mDNSResponder on Mac OS X and is used to advertise services to the network. By creating a basic XML file and attaching it to Avahi, your service will be advertised as long as the system is running. Using Avahi gives you the flexibility to advertise any service (not just Apache/HTTP) and is also a lot simpler to get up and running. I will outline both approaches here.

Zeroconf using mod_dnssd

  1. Install mod_dnssd: sudo apt-get install libapache2-mod-dnssd
  2. Import the module into Apache and enable it
    Open your Apache config file (e.g. /etc/apache2/apache2.conf) and add the following lines to the top:
    LoadModule dnssd_module /usr/lib/apache2/modules/mod_dnssd.so
    DNSSDEnable on
  3. Restart Apache with the new settings:
    /etc/init.d/apache2 restart

Zeroconf using Avahi

    1. Create a new file in /etc/avahi/services called http.service
    2. Add the following:
<?xml version="1.0" standalone='no'?>
<!DOCTYPE service-group SYSTEM "avahi-service.dtd">
<service-group>
  <name>MyWeb</name> ## Name of the service
  <service>
    <type>_http._tcp</type>
    <port>80</port>
  </service>
</service-group>
  1. You don’t even need to restart Avahi, your new service will automatically start broadcasting!

One Response to “How to enable Zeroconf for Apache”

Leave a Reply