当前位置:   article > 正文

使用Apache配置多个网站

apache配置多个网站

准备 

首先确保安装了Apache,没有则使用如下命令安装:

yum -y install httpd

启动Apache

systemctl start httpd

 

目录

准备 

1 环境准备

 1.1 关闭防火墙

 1.2 关闭SeLinux

2 配置

3 创建目录

4 创建主页文件

5 向主页文件中添加内容

6 修改/etc/hosts文件

7 重启Apache服务

8 测试


1 环境准备

 1.1 关闭防火墙

systemctl stop firewalld

永久关闭防火墙

systemctl disable firewalld

 1.2 关闭SeLinux

修改配置文件

vi /etc/selinux/config

#将SELINUX=enforcing修改为SELINUX=disabled

setenforce 0

2 配置

编辑Apache主配置文件

vi /etc/httpd/conf/httpd.conf

添加如下内容:

  1. <VirtualHost 192.168.10.124>
  2. DocumentRoot "/var/www/html"
  3. ServerName www.111.com
  4. <Directory "/var/www/html">
  5. AllowOverride None
  6. Require all granted
  7. </Directory>
  8. </VirtualHost>
  9. <VirtualHost 192.168.10.124>
  10. DocumentRoot "/var/www/log"
  11. ServerName www.222.com
  12. <Directory "/var/www/log">
  13. AllowOverride None
  14. Require all granted
  15. </Directory>
  16. </VirtualHost>

3 创建目录

创建/var/www/log

mkdir /var/www/log

4 创建主页文件

在网站根目录/var/www/html下面创建一个主页文件【!!!切记,创建的后缀必须是html】

  1. cd /var/www/html
  2. touch index.html

同时,在/var/www/log下面创建主页文件

  1. cd /var/www/log
  2. touch index.html

 

5 向主页文件中添加内容

  1. echo "这是www.111.com">/var/www/html/index.html
  2. echo "这是www.222.com">/var/www/log/index.html

6 修改/etc/hosts文件

vi /etc/hosts

添加如下内容:

  1. 192.168.10.124 www.111.com
  2. 192.168.10.124 www.222.com

7 重启Apache服务

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

8 测试

curl www.111.com
curl www.222.com

成功!

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/代码探险家/article/detail/851481
推荐阅读
相关标签
  

闽ICP备14008679号