Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

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" .
./sites-available/default:<VirtualHost 192.168.0.82:80>
./httpd.conf:<VirtualHost 192.168.0.82:80>
./ports.conf:NameVirtualHost 192.168.0.82:80
./sites-enabled/000-default:<VirtualHost 192.168.0.82:80>

There's no mention of listening on 0.0.0.0.

/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 0.0.0.0:80
no listening sockets available, shutting down
Unable to open logs
Action 'start' failed.
The Apache error log may have more information.
                                                                         [fail]

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

/etc/apache2$ sudo netstat -nap | grep :80
tcp        0      0 192.168.0.83:80       0.0.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
1  
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 192.168.0.82:80 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

4 Answers 4

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:

Listen 192.168.0.82:80

Reference: http://httpd.apache.org/docs/2.2/bind.html

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 (0.0.0.0)
#
#Listen 12.34.56.78:80

For what you want, change the Listen 80 line to Listen 192.168.0.82:80.

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

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
1  
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
1  
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:

Listen 192.168.0.82:80

More info in documentation.

share|improve this answer

Use the following as per the Apache docs:

Listen 192.168.0.82:80

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

 
discard

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.