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:
<VirtualHost *:80>
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:
<VirtualHost xxx.xxx.xxx.xxx:80>
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:
Listen 80
<IfModule mod_ssl.c>
Listen 443
</IfModule>
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:
Listen xx.xx.xxx.xxx:80
Listen xx.xx.xxx.xxx:80<IfModule mod_ssl.c>
Listen 443
</IfModule>
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
Rahood says
By default Apache listens to port 80 on all IP addresses on the HOST machine. Listen and BindAddress are well documented should you slice and dice using VirtualHost Have a good look at your httpd.conf if you do not specify example.com:21 It will revert back to port 80. Directives within VirtualHost apply to just THAT virtual host and will override the configuration of the HOST server. The bottom line is that I have found it good practice to run nothing on the host. Push all requests off to the VirtualHost …if you are going to use VH gap the server from it’s siblings.
http://httpd.apache.org/docs/1.3/vhosts/name-based.html
//any word on p.ie ?
Some say a week is a long time in Politics but God only knows what a week is worth on the Web.