Issues with running Apache on one IP

apache-2.4ubuntu-14.04

I currently have a machine with multiple IPs, however I wish to limit Apache to just one of them.

I understand this question has been asked already here however I have run into issues following it: Limit Apache to a single IP

For the sake of simplicity, lets say I have an IP, 1.1.1.1 which I want Apache to run on, meanwhile another IP, 2.2.2.2 is available to Apache however I do not want Apache to touch this IP.

In my ports.conf:

Listen 1.1.1.1:80

<IfModule ssl_module>
    Listen 1.1.1.1:443
</IfModule>

<IfModule mod_gnutls.c>
    Listen 1.1.1.1:443
</IfModule>

Meanwhile, 000-default.conf:

<VirtualHost *:80>
    ServerAdmin webmaster@localhost
    DocumentRoot /var/www/html
    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

Using the configuration, there are no errors on startup, however when visiting 1.1.1.1 in a browser, it appears to take me no to /var/www/html (the default Apache2 page) but rather to one of my sites currently running on the IP too.

Additonally, using:

<VirtualHost 1.1.1.1:80>

Appear to allow you to visit 1.1.1.1 in browser and get /var/www/html (the default Apache2 page) yet on startup using this configuration gives the error:

[Tue Aug 18 17:34:54.487039 2015] [core:error] [pid 5446] (EAI 2)Name or service not known: AH00549: Failed to resolve server name for 1.1.1.1 (check DNS) -- or specify an explicit ServerName

I am stumped by this one, if anyone could show me as to what is going wrong, that would be great.

Best Answer

...or specify an explicit ServerName - here's the point. You have to be missing ServerName your.fqdn in your configuration. Ubuntu's httpd doesn't have it by default.

Go with <VirtualHost *:80> version. Create /etc/apache2/conf-available/servername.conf, put ServerName your.fqdn there, run a2enconf servername, then service apache2 reload. Remember to also set ServerName inside every VirtualHost block (may be skipped for default one).

Other than that, your IP configuration seems fine. Make sure 000-default.conf is enabled (a link present in /etc/apache2/sites-enabled).