Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I've got a server with a bunch of IP addresses, and I only want Apache listening on one of them. It doesn't sound like a hard thing to do, and I've done it once before a while ago, but I'm having some trouble this time around. First off, here's where I'm at now, to my understanding:

Every place Apache is listening to port 80, it's listening only on the correct IP.

/etc/apache2$ grep -R ":80" .

There's no mention of listening on

/etc/apache2$ grep -R "0\.0\.0\.0" .

And yet... Apache refuses to start.

/etc/apache2$ sudo /etc/init.d/apache2 start
 * Starting web server apache2
(98)Address already in use: make_sock: could not bind to address
no listening sockets available, shutting down
Unable to open logs
Action 'start' failed.
The Apache error log may have more information.

In case someone asks, I'm not bound to that address:

/etc/apache2$ sudo netstat -nap | grep :80
tcp        0      0*        LISTEN      2822/node

The error log at /var/log/apache2/error.log just says:

[Wed Aug 08 03:30:18 2012] [notice] caught SIGTERM, shutting down

Have I missed a spot in Apache's config? Is there something I'm not remembering to look for? Why is this not as simple as I remembered it being?

share|improve this question
I'm not offended or anything, but could you please explain how you selected the best answer of this question? The answer you selected was referencing another distro, while my answer was spot-on in regards to Ubuntu. Could I have made my answer different in any way since you didn't select it? – pauska Aug 8 '12 at 12:13
@Dan, yes, you should award the accepted answer to Pauska. – cjc Aug 8 '12 at 13:11
Both of your answers contained the critical Listen line, which is what I needed. I selected cjc's answer because it went into a bit more depth as to why that line was needed. I thought mentioning the comments used in the version of Apache that comes packaged with CentOS was a nice addition. But since everyone seems to be in general agreement that the answer should go to pauska, I've gone ahead and given it to him. After all, I notice by looking at the revisions that pauska's comment significantly influenced cjc's answer in its current form. – Dan Aug 9 '12 at 13:31
up vote 16 down vote accepted

Apache binds to everything by default, even if you specify certain IP('s) to run NameVirtualHost on.

Add this in your ports.conf:



share|improve this answer

Look in the /etc/apache2/ports.conf file.

You'll find a directive like:

Listen 80

The comment on CentOS boxes describes this option:

# Listen: Allows you to bind Apache to specific IP addresses and/or
# ports, in addition to the default. See also the <VirtualHost>
# directive.
# Change this to Listen on specific IP addresses as shown below to
# prevent Apache from glomming onto all bound IP addresses (

For what you want, change the Listen 80 line to Listen

You are not able to start Apache right now because it is attempting to bind to port 80 on all interfaces (the designation), and you have node listening on

The IP in the virtual host blocks means that that particular virtual host will respond on requests coming in on that IP address. It doesn't specify how Apache will bind to the interfaces it sees.

share|improve this answer
The httpd.conf is blank on Ubuntu, as they use a different style of configuration files (lots of includes). There isn't any "Listen 80" either, as the grep's from the OP showed. – pauska Aug 8 '12 at 10:38
Oh, right. Ubuntu. I'll update. The grep he was doing was against :80 so it was going to miss things anyway, as the default is Listen 80. – cjc Aug 8 '12 at 11:06
That CentOS comment really would have helped my out. Silly Ubuntu... – Dan Aug 8 '12 at 11:16

Listen directive is what you're looking for:


More info in documentation.

share|improve this answer

Use the following as per the Apache docs:


In some circumstances (not all), one could go a bit further and do this:

Listen some_name_in_my_localhost:80

That way you make your apache configs portable in situations when you have an Apache server farm. There are pros and cons to this (just like with everything else.)

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.