CentOS7 yum安装Apache(httpd)并实现多域名配置

By 肖奈
2017-08-20
3528 read

系统环境:本地服务器CentOS 7.2 x64

一、Apache(httpd)安装 
安装

yum install httpd1

设置自启

systemctl enable httpd.service1

二、软件配置 
编辑httpd.conf就够了,httpd.conf在/etc/httpd/conf中

vim /etc/httpd/conf/httpd.conf1

1、用#注释掉以下两行(其实如果不注释,好像没有什么影响)

#ServerName www.example.com#DocumentRoot /var/www/html12

2、开放目录使用权限 
在httpd.conf中写入,引号中的路径是自定义的开放访问的路径,其子目录也开放使用。 
如果不写这个段落,网页会被重定向到默认页面,虚拟主机中的自定义路径设置无效。 
Directory里的东西必修要写,不写就打不开。。。亲测

<Directory "/home/www">    Options Indexes FollowSymLinks
    AllowOverride None
    Require all granted
</Directory>12345

3、写入虚拟主机信息 
①开启虚拟主机并确定其监听的主机名与端口,* 表示省略,80为网页默认端口。

NameVirtualHost *:801

②写入单个虚拟主机信息 
ServerName —— 主机名(域名或公网IP) 
ServerAlias —— 别名(二级域名或其他域名或IP) 
DocumentRoot —— 文件目录(表示将域名映射至该文件目录)。 
按照模版有几个写几个,不知道有没有上限。。。 
虚拟主机的文件目录必须在上述的开放访问的目录下,不然无法访问。 
模版:

<VirtualHost *:80>
    ServerName XXX    ServerAlias XXX2    DocumentRoot /XXX</VirtualHost>123456

三、完整过程 
示例仅供参考,如有其他需要,请根据情况自行修改。 
1、控制台命令

yum install httpd
systemctl enable httpd.servicesystemctl start httpd.servicevim /etc/httpd/conf/httpd.conf12345

2、httpd.conf修改(略去不用修改的部分)

#ServerName www.example.com#DocumentRoot /var/www/html<Directory "/home/www">
    Options Indexes FollowSymLinks    AllowOverride None    Require all granted</Directory>NameVirtualHost *:80<VirtualHost *:80>
    ServerName www.mywebsite1.com    DocumentRoot /home/www/htmla</VirtualHost><VirtualHost *:80>
    ServerName mywebsite1.com    DocumentRoot /home/www/htmlb</VirtualHost><VirtualHost *:80>
    ServerName www.mywebsite2.com    ServerAlias mywebsite2.com    DocumentRoot /home/www/htmlc</VirtualHost>


linux httpd.conf详解
python img的操作

Comments

暂无评论,还不快来坐沙发...

Leave a Reply