我使用静态 IP 地址(不是 FQDN)在 Rackspace 机器上设置 Centos 6.3。我将在此机器上设置虚拟主机,它似乎工作正常,但是当我重新启动 HTTPD 服务器时,我收到一条错误消息“无法可靠地确定服务器的完全限定域名,使用 xx.xxx.xx.xx 作为 ServerName”(xx.xxx.xx.xx 是服务器的静态 IP 地址)。
我的/etc/hosts 中有以下内容:
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 是我创建服务器时使用的名称(不是 FQDN)(您必须输入名称)。
我假设我可能不需要更改/etc/hosts 中的任何内容,但是我应该在 httpd.conf 中放入什么内容?现在,我在该文件中有以下内容:
NameVirtualHost *:80
<VirtualHost *:80>
DocumentRoot /var/www/html
ServerName localhost
<Directory /var/www/html>
allow from all
Options +Indexes
</Directory>
</VirtualHost>
我还尝试将 ServerName 设置为 xx.xxx.xx.xx,但收到了相同的错误消息。
最佳答案
此错误是因为您没有使用 FQDN。它不应影响网络服务器的运行。
要在启动时消除该消息,您需要使用正确的域和 IP 地址配置主机文件。您的 httpd.conf 也应该使用相同的名称(指定了 localhost)。
只要您的服务器正在启动并且您不打算为您的网络服务器分配域,则可以忽略此错误。
具有 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>
主机文件示例:
127.0.0.1 localhost localhost.localdomain gentoo1
x.x.x.x gentoo1.domain.net
关于linux - 如何使用静态 IP 地址设置主机和 httpd.conf 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12846784/