linux - apache配置文件中的ServerName究竟指什么?
阿神
阿神 2017-04-17 16:07:08
0
2
1241

我们给定一个具体的场景:

域名:  xyz.com
dns服务器   ns1.xxx.com
将绑定的ip地址  123.123.123.123
apache2安装在  123.123.123.123

在apache2的配置文件/etc/httpd/conf/httpd.conf中,有两个地方会出现ServerName。
第一个地方:

ServerName gives the name and port that the server uses to identify itself.
This can often be determined automatically, but we recommend you specify
it explicitly to prevent problems during startup.
If your host doesn't have a registered DNS name, enter its IP address here.

ServerName localhost:80

这里的ServerName localhost:80 是否可以修改成
ServerName 123.123.123.123:80
我理解成这样,是根据英语
If your host doesn't have a registered DNS name, enter its IP address here.
问题来了:如果我的主机有registered DNS name,应当如何处理呢?

第二个地方
你需要写下面这样的代码

<VirtualHost *:80>
    ServerName www.xyz.com
    DocumentRoot "/var/www/html"
</VirtualHost>

从上面,我们可以看出:都是ServerName,但是他们对应的具体值,不一样。
1。我的理解对吗?
2。两个地方,我都写对了吗?
3。还有个问题:如果我的主机有registered DNS name,应当如何处理呢?

阿神
阿神

闭关修行中......

reply all(2)
小葫芦
<VirtualHost *:80>
    ServerName www.xyz.com
    DocumentRoot "/var/www/html"
</VirtualHost>

This configuration is correct and is used to bind the domain name. If this domain name is yours and your server happens to have a public IP, resolve www.xyz.com to your IP. You can access it through www.xyz.com. www.xyz.com到你的IP上,就可以通过www.xyz.com访问。

但我知道www.xyz.com肯定不是你的,所以你还可以在本地修改host
But I know that www.xyz.com is definitely not yours, so you can also modify host locally, so that you can also enjoy this domain name locally.

In this way, multiple domain names and multiple directories can be bound to port 80. Different domain names correspond to different directories, and different pages are displayed when accessed. 🎜
小葫芦

In fact, the first default does not need to be changed, unless the reverse parsing is wrong. Don’t worry if the server can start normally. If it cannot start normally because of this, change the domain name to A record

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template