我需要设置Apache服务器名称吗?

6

我不确定SO是否是提问这个问题的地方 - 如果不是,请告诉我。我考虑过superuser,但它似乎并不符合他们的faq规范。

无论如何 - 问题是什么!如果我只是使用服务器为单个网站提供服务,那么我是否需要在apache2.conf文件中输入ServerName值?如果是,我应该设置为什么?

我正在按照这个指南进行操作:

http://meppum.com/2009/jan/17/installing-django-ubuntu-intrepid/

它建议我在我的apache2.conf文件中设置"SeverName"选项。我查看了相关内容并发现了这篇文章,讨论了"ServerName"。

http://www.linuxhomenetworking.com/wiki/index.php/Quick_HOWTO_:Ch20:_The_Apache_Web_Server

这很有趣,但并没有告诉我何时需要设置ServerName。据我判断,只有在执行类似something.domainname.com的操作时才需要,比如answers.yahoo.com。
这是正确的吗?如果不是,那么对于一个名为www.yahoo.com的域名,在192.0.0.1上,servername应该是什么?
1个回答

5
如果服务器只托管一个网站,则不必使用VirtualHosts,因此也不必定义ServerName,但建议这样做。
如果未定义ServerName,则Apache将尝试根据服务器IP执行反向DNS查找来查找主机名。
根据Apache文档

The ServerName directive sets the request scheme, hostname and port that the server uses to identify itself. This is used when creating redirection URLs.

Additionally, ServerName is used (possibly in conjunction with ServerAlias) to uniquely identify a virtual host, when using name-based virtual hosts.

For example, if the name of the machine hosting the web server is simple.example.com, but the machine also has the DNS alias www.example.com and you wish the web server to be so identified, the following directive should be used:

 ServerName www.example.com

ServerName www.example.com If no ServerName is specified, then the server attempts to deduce the hostname by performing a reverse lookup on the IP address. If no port is specified in the ServerName, then the server will use the port from the incoming request. For optimal reliability and predictability, you should specify an explicit hostname and port using the ServerName directive.

回答你的问题:

如果我只是使用服务器为单个网站提供服务,那么我是否需要在我的apache2.conf文件中输入ServerName值?

不需要,但建议这样做。

如果需要,在ServerName中应该设置什么?

语法为:ServerName [scheme://]fully-qualified-domain-name[:port]

这是唯一的情况吗?

不是唯一的情况。

如果不是,那么服务器名称(例如,对于名为192.0.0.1的www.yahoo.com域)应该是什么?

ServerName www.yahoo.com


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接