Until yesterday evening I had never had any reason to configure multiple services on the same port, so I'd never had any reason to delve into the configuration changes to make this happen.
In order to get this working you have to have more than one IP address available.
In my case I have 3 assigned to the server in question. The main IP is used for serving most of the sites, while I had one assigned to it for running a particular service.
Up until now Apache was happily listening on all IP addresses / interfaces so the Apache configuration directives were quite simple. Simple is always best, so long as it works. The more complicated you make it the more likely you are to run into issues.
In the original Apache config I was using virtual hosts that relied more on DNS than apache to decide what was being served:
The "*" means that it is listening on all IP addresses / interfaces for connections.
Moving a service to a specific IP means that the configuration has to be changed to avoid conflicts, so all the Apache VirtualHosts need to be told which IP to use:
where you replace the "xxx" with the IP you are using.
In my innocence I presumed that this would fix everything up, but I hadn't counted on one small but important thing. Apache was configured at a higher level to listen to ALL Ips and interfaces.
The Listen directive is now required, as I'm using the latest available version of Apache for my OS:
The Listen directive instructs Apache to listen to only specific IP addresses or ports; by default it responds to requests on all IP interfaces. Listen is now a required directive. If it is not in the config file, the server will fail to start. This is a change from previous versions of Apache.
The Listen directive tells the server to accept incoming requests on the specified port or address-and-port combination. If only a port number is specified, the server listens to the given port on all interfaces. If an IP address is given as well as a port, the server will listen on the given port and interface.
Multiple Listen directives may be used to specify a number of addresses and ports to listen to. The server will respond to requests from any of the listed addresses and ports.
On Ubuntu (and probably Debian, though I can only guess) Apache's configuration files are split up into manageable chunks which reside in /etc/apache2
The one which dictates which ports to use and which IPs those ports are assigned to is aptly named ports.conf
The default setting is:
As no IP address is specified the server will listen to any available.
To force it to only use a couple of your IPs you need to explicitly tell it which ones to use:
You can add IPv4 or IPv6 addresses in with ease.
With that final change made I was able to get both servers up and running on the same machine using the same port, but different IPs.
Now if only I could get the service to work the way I wanted it to I'd be happy