首先确保安装了Apache,没有则使用如下命令安装:
yum -y install httpd
启动Apache
systemctl start httpd
?
目录
systemctl stop firewalld
永久关闭防火墙
systemctl disable firewalld
修改配置文件
vi /etc/selinux/config
#将SELINUX=enforcing修改为SELINUX=disabled。
setenforce 0
编辑Apache主配置文件
vi /etc/httpd/conf/httpd.conf
添加如下内容:
<VirtualHost 192.168.10.124>
DocumentRoot "/var/www/html"
ServerName www.111.com
<Directory "/var/www/html">
AllowOverride None
Require all granted
</Directory>
</VirtualHost>
<VirtualHost 192.168.10.124>
DocumentRoot "/var/www/log"
ServerName www.222.com
<Directory "/var/www/log">
AllowOverride None
Require all granted
</Directory>
</VirtualHost>
创建/var/www/log
mkdir /var/www/log
在网站根目录/var/www/html下面创建一个主页文件【!!!切记,创建的后缀必须是html】
cd /var/www/html
touch index.html
同时,在/var/www/log下面创建主页文件
cd /var/www/log
touch index.html
?
echo "这是www.111.com">/var/www/html/index.html
echo "这是www.222.com">/var/www/log/index.html
vi /etc/hosts
添加如下内容:
192.168.10.124 www.111.com
192.168.10.124 www.222.com
systemctl restart httpd
【如果出现Job for httpd.service failed because the control process exited with error code. See "systemctl status httpd.service" and "journalctl -xe" for details. ,则表示刚才编辑Apache主配置文件(/etc/httpd/conf/httpd.conf)有问题】
如果想更快确定文件哪有问题,使用如下命令查看:
systemctl status httpd.service
curl www.111.com
curl www.222.com
成功!