Linux – How to set up the hosts and httpd.conf files using a static IP address

apachecentoslinux

I set Centos 6.3 up on a Rackspace box, using a static IP address (not a FQDN). I will be setting up virtual hosts on this box, and it seems to be working fine, but when I restart the HTTPD server, I get an error message "could not reliably determine the server's fully qualified domain name, using xx.xxx.xx.xx for ServerName" (xx.xxx.xx.xx is the static IP address for the server).

My /etc/hosts has the following in it:

27.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6
xx.xxx.xx.xx    name-used-for-rackspace

name-used-for-racspace is a name (not a FQDN) I used when I created the server (you have to enter a name).

I assume that I may not have to change anything in /etc/hosts, but what do I put in httpd.conf? right now, I have the following in that file:

NameVirtualHost *:80
<VirtualHost *:80>
    DocumentRoot /var/www/html
    ServerName localhost 
    <Directory /var/www/html>
            allow from all
            Options +Indexes
    </Directory>
</VirtualHost>

I also tried setting ServerName to xx.xxx.xx.xx, but I got the same error message.

Best Answer

This error is because you are not using a FQDN. It should not affect the operation of the webserver.

To get rid of the message on startup you'd need to configure your hosts file with the correct domain and IP address. Your httpd.conf should also use the same name (where you have localhost specified).

As long as your server is starting and you don't plan on assigning a domain to your webserver, this error can be ignored.

Example virtual host with FQDN:

<VirtualHost *:80>
ServerName www.domain.net
ServerAlias domain.net *.domain.net
ServerAdmin administrator@domain.net
DocumentRoot "/home/domain/htdocs"
<Directory "/home/domain/htdocs">
        Options Indexes FollowSymLinks
        AllowOverride All
        Order allow,deny
        Allow from all
</Directory>
CustomLog "/home/domain/logs/access-www.log" common
ErrorLog "/home/domain/logs/error-www.log"

        <IfModule mpm_peruser_module>
          ServerEnvironment apache apache
        </IfModule>
</VirtualHost>

Example hosts file:

127.0.0.1       localhost       localhost.localdomain gentoo1
x.x.x.x         gentoo1.domain.net