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

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

域名:  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,应当如何处理呢?

阿神
阿神

闭关修行中......

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

这个配置是正确的,用于绑定域名的,如果这个域名是你的,恰巧你的这个服务器有公网IP,解析www.xyz.com到你的IP上,就可以通过www.xyz.com访问。

但我知道www.xyz.com肯定不是你的,所以你还可以在本地修改host,这样你也可以本地独享这个域名了。
这样可以在80端口上绑定多个域名,并且多目录,不同域名对应到不同的目录,访问展示不一样的页面。

小葫芦

其实第一个默认是不需要改的,除非反向解析不对。服务器能正常启动不用管,如果是因为这个不能正常启动的话就改成A记录那个域名

Beliebte Tutorials
Mehr>
Neueste Downloads
Mehr>
Web-Effekte
Quellcode der Website
Website-Materialien
Frontend-Vorlage
Über uns Haftungsausschluss Sitemap
Chinesische PHP-Website:Online-PHP-Schulung für das Gemeinwohl,Helfen Sie PHP-Lernenden, sich schnell weiterzuentwickeln!