1

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.

1 Answer 1

0

...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).

3
  • Sorry, I don't understand what you mean, leave everything as it is and create a file called 'servername.conf' in /etc/apache2/conf-available/servername.conf and run a2enconf servername? What should I actually put in the servername.conf file? Remember I am running multiple sites off the one IP. Sorry, I am really new to all this.
    – dwilson390
    Aug 18, 2015 at 17:00
  • Edited the answer to make 2nd paragraph more clear. The proposed change doesn't interfere with name-based virtual hosting that you probably have configured (I assume this is what you mean by multiple sites off the one IP). Aug 18, 2015 at 18:22
  • Thank you, you helped me solve this issue. For reference, all virtual hosts need to use *:80 which is what was causing the issues regarding the server serving the wrong site.
    – dwilson390
    Aug 18, 2015 at 20:17

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .