二、說(shuō)明Linux版本CentOS release 6.9 (Final):

[root@ etc]# cat /etc/redhat-releaseCentOS release 6.9 (Final)


A" />

国产成人精品无码青草_亚洲国产美女精品久久久久∴_欧美人与鲁交大毛片免费_国产果冻豆传媒麻婆精东

18143453325 在線咨詢 在線咨詢
18143453325 在線咨詢
所在位置: 首頁(yè) > 營(yíng)銷資訊 > 建站知識(shí) > CentOS: Apache多域名多站點(diǎn)配置

CentOS: Apache多域名多站點(diǎn)配置

時(shí)間:2023-02-07 16:36:01 | 來(lái)源:建站知識(shí)

時(shí)間:2023-02-07 16:36:01 來(lái)源:建站知識(shí)



一、目標(biāo)

在centos6.9下配置Web服務(wù)器Apache2.2.15版本,添加多個(gè)Web站點(diǎn)多域名,且共用80端口。

二、說(shuō)明

Linux版本CentOS release 6.9 (Final):

[root@ etc]# cat /etc/redhat-releaseCentOS release 6.9 (Final)


Apache版本Apache/2.2.15 (Unix):

[root@ etc]# httpd -vServer version: Apache/2.2.15 (Unix)Server built: Oct 19 2017 16:43:38


三、步驟

1.修改Apache httpd.conf 默認(rèn)配置文件




本機(jī)配置目錄/etc/httpd/conf/httpd.conf

Apache需要重定向功能,可在httpd.conf開啟mod_rewrite模塊功能:

LoadModule rewrite_module modules/mod_rewrite.so


?#vhost conf fileInclude "vhost/*.conf"?


2.修改vhost中虛擬站點(diǎn)配置文件

在配置目錄/etc/httpd/conf同級(jí)目錄下創(chuàng)建vhost文件夾,您可以通過(guò)修改vhost里的xxx.conf文件來(lái)增加、刪除或修改您的二級(jí)域名和所指向的實(shí)際路徑,不需要重啟Apache服務(wù)。:

[root@ httpd]# pwd/etc/httpd[root@ httpd]# lltotal 12drwxr-xr-x 2 root root 4096 Jun 28 19:46 confdrwxr-xr-x 2 root root 4096 Oct 24 2017 conf.dlrwxrwxrwx 1 root root 19 Oct 24 2017 logs -> ../../var/log/httpdlrwxrwxrwx 1 root root 29 Oct 24 2017 modules -> ../../usr/lib64/httpd/moduleslrwxrwxrwx 1 root root 19 Oct 24 2017 run -> ../../var/run/httpddrwxr-xr-x 2 root root 4096 Jun 28 19:47 vhost


web1.conf文件可以自定義

<VirtualHost *:80> ServerAdmin 1184795629@qq.com DocumentRoot /var/code/mallServerName www.xxx.cn ServerAlias xxx.cn<Directory "/var/code/mall"> Options Indexes FollowSymLinks AllowOverride all Order allow,deny Allow from all</Directory></VirtualHost>


web2.conf文件可以自定義

<VirtualHost *:80> ServerAdmin 1184795629@qq.com DocumentRoot /var/code/mallServerName mall.phpersay.cn <Directory "/var/code/mall"> Options Indexes FollowSymLinks AllowOverride all Order allow,deny Allow from all</Directory></VirtualHost>


web3.conf文件可以自定義

<VirtualHost *:80> ServerAdmin 1184795629@qq.com DocumentRoot /var/code/blogServerName www.phpersay.cn <Directory "/var/code/blog"> Options Indexes FollowSymLinks AllowOverride all Order allow,deny Allow from all</Directory></VirtualHost>





3.重啟apache讓配置生效

重啟web服務(wù)器Apache的進(jìn)程httpd

[root@ etc]#service httpd restart


4.測(cè)試效果

web1站點(diǎn)訪問正常,web2、web3訪問的結(jié)果始終是web1的頁(yè)面。配置存在問題。




四、遇到的問題

網(wǎng)友有云:hosts文件需要映射

增加配置

127.0.0.1 phpersay.com127.0.0.1 mall.phpersay.com127.0.0.1 xxxx.cn重啟網(wǎng)絡(luò)

[root@ etc]# /etc/init.d/network重啟web服務(wù)器Apache的進(jìn)程httpd

[root@ etc]#service httpd restartStopping httpd: [ OK ]Starting httpd: [ OK ]然并非有用答案。




排查階段:

首先確認(rèn)語(yǔ)法拼寫是否有誤,

無(wú)誤。

問題原因定位:

開啟Apache的虛擬主機(jī)功能

#NameVirtualHost *:80


其他錯(cuò)誤

Starting httpd: [Mon Jun 28 23:37:17 2021] [warn] NameVirtualHost xxx.xx.xx.110:80 has no VirtualHosts

[root@iZ23hnwptztZ etc]# service httpd restartStopping httpd: [ OK ]Starting httpd: [Mon Jun 28 18:40:25 2021] [warn] NameVirtualHost xxx.xx.xx.110:80 has no VirtualHosts [ OK ]引起這個(gè)警告的原因是NameVirtualHost語(yǔ)法錯(cuò)誤 ,對(duì)于同一主機(jī)支持多個(gè)虛擬主機(jī)的情況,只需要命名一次NameVirtualHost,如果在每個(gè)虛擬主機(jī)配置文件中都加上NameVirtualHost *:80 ,則會(huì)報(bào)這個(gè)警告。

httpd.conf

NameVirtualHost *:80NameVirtualHost xxx.xx.xx.xxx:80vhost/web.conf

<VirtualHost *:80> ServerAdmin 1184795629@qq.com DocumentRoot /var/code/blogServerName www.phpersay.cn <Directory "/var/code/blog"> Options Indexes FollowSymLinks AllowOverride all Order allow,deny Allow from all</Directory></VirtualHost>錯(cuò)誤原因就是在httpd.conf文件中,重復(fù)定義了NameVirtualHost,刪除該行,重啟Apache即可。







關(guān)鍵詞:配置

74
73
25
news

版權(quán)所有? 億企邦 1997-2025 保留一切法律許可權(quán)利。

為了最佳展示效果,本站不支持IE9及以下版本的瀏覽器,建議您使用谷歌Chrome瀏覽器。 點(diǎn)擊下載Chrome瀏覽器
關(guān)閉