服務(wù)器維護Apache 2.4.6 多域名多網(wǎng)站配置
2020-06-25 11:18 作者:admin
服務(wù)器維護小知識近日因為需要,需要在一個公網(wǎng)IP的服務(wù)器上配置多個網(wǎng)站,不同的域名訪問不同的網(wǎng)站,用到了Apache的Virtualhost
服務(wù)器維護小知識系統(tǒng)環(huán)境:
CentOS 7 + Apache 2.4.6 + PHP + MySQL
# 創(chuàng)建網(wǎng)站目錄
mkdir -p /var/www/linuxidc.com/public_html # 帥旗軍個人博客
mkdir -p /var/www/hmgzh.net/public_html # 黃梅公眾號網(wǎng)站
# www目錄755權(quán)限
chmod -R 755 /var/www
# 創(chuàng)建主頁
vi /var/www/linuxidc.com/public_html/index.html #添加任意內(nèi)容
# 創(chuàng)建Virtual配置目錄
mkdir /etc/httpd/sites-available
mkdir /etc/httpd/sites-enabled
# 配置httpd.conf
vi /etc/httpd/conf/httpd.conf
# 添加以下內(nèi)容
IncludeOptional sites-enabled/*.conf
注釋掉# DocumentRoot "/var/www/html"
# 創(chuàng)建網(wǎng)站Virtual配置文件
vi /etc/httpd/sites-available/linuxidc.com.conf
# 添加以下內(nèi)容
<VirtualHost *:80>
ServerName
www.linuxidc.com
ServerAlias linuxidc.com
DocumentRoot /var/www/linuxidc.com/public_html
</VirtualHost>
<Directory "/var/www/linuxidc.com">
Options +Includes -Indexes
AllowOverride All
Require all granted
</Directory>
#創(chuàng)建鏈接
ln -s /etc/httpd/sites-available/linuxidc.com.conf /etc/httpd/sites-enabled/linuxidc.com.conf
#配置HOSTS
vi /etc/hosts
# 更改如下
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
10.100.18.100 linuxidc.com
10.100.18.100 hmgzh.net
#重啟Apache
systemctl restart httpd
IT運維 我們選擇
北京艾銻無限
以上文章由北京艾銻無限科技發(fā)展有限公司整理