1. 程式人生 > >Apache 2.4.6 多域名多網站配置

Apache 2.4.6 多域名多網站配置

用的是Centos7.2 64位的系統
Apache 2.4.6

安裝Apache

# 檢視httpd包是否可用:
yum list | grep httpd

#安裝Apache
yum install httpd

修改配置檔案

進入配置檔案目錄

cd /etc/httpd/conf

檢視是否有httpd.conf

ls

將原有配置檔案備份

cp httpd.conf httpd.conf.bak

找到配置檔案中的

DocumentRoot"/var/www/html"

編輯配置檔案

vi /etc/httpd/conf/httpd.conf

新增以下內容

IncludeOptional sites-enabled/*.conf

註釋掉DocumentRoot “/var/www/html”

建立Virtual配置目錄

mkdir /etc/httpd/sites-available
mkdir /etc/httpd/sites-enabled

建立網站目錄

mkdir -p /var/www/fresh

www目錄755許可權

chmod -R 755 /var/www

建立網站Virtual配置檔案

vi /etc/httpd/sites-available/fresh.hnjdzj.cn.conf

新增以下內容

<VirtualHost *:80>
ServerName fresh.hnjdzj.cn ServerAlias fresh.hnjdzj.cn DocumentRoot /var/www/fresh </VirtualHost> <Directory "/var/www/fresh"> Options +Includes -Indexes AllowOverride All Require all granted </Directory>

建立軟連結

ln -s /etc/httpd/sites-available/fresh.hnjdzj.cn.conf
/etc/httpd/sites-enabled/fresh.hnjdzj.cn.conf

配置HOSTS

vi /etc/hosts

新增

127.0.0.1 fresh.hnjdzj.cn

重啟Apache

systemctl restart httpd