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

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

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

阿神
阿神

闭关修行中......

全部回覆(2)
小葫芦
<VirtualHost *:80>
    ServerName www.xyz.com
    DocumentRoot "/var/www/html"
</VirtualHost>

這個設定是正確的,用於綁定網域的,如果這個網域是你的,剛好你的這個伺服器有公網IP,解析www.xyz.com到你的IP上,就可以透過www.xyz.com存取。 www.xyz.com到你的IP上,就可以通过www.xyz.com访问。

但我知道www.xyz.com肯定不是你的,所以你还可以在本地修改host
但我知道www.xyz.com絕對不是你的,所以你還可以在本地修改host,這樣你也可以本地獨享這個網域了。

這樣可以在80埠上綁定多個域名,並且多目錄,不同域名對應到不同的目錄,訪問展示不一樣的頁面。 🎜
小葫芦

其實第一個預設是不需要改的,除非反向解析不對。伺服器能正常啟動不用管,如果是因為這個不能正常啟動的話就改成A記錄那個網域

熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板
關於我們 免責聲明 Sitemap
PHP中文網:公益線上PHP培訓,幫助PHP學習者快速成長!