首页
学习
活动
专区
圈层
工具
发布
社区首页 >专栏 >Centos7下多种方式配置 Apache虚拟主机

Centos7下多种方式配置 Apache虚拟主机

作者头像
释然IT杂谈
发布于 2020-06-12 10:36:17
发布于 2020-06-12 10:36:17
1.2K0
举报
文章被收录于专栏:释然IT杂谈释然IT杂谈
一、虚机主机的三种方式

1、基于IP

2、基于IP+端口

3、基于域名

官网文档:http://httpd.apache.org/docs/2.4/

二、安装Apache

1、系统环境

2、yum安装

可以查看安装了内容

3、配置Selinux文件,SELINUX=disabled。

[root@localhost ~]# vim /etc/selinux/config

SELINUX=disabled

SELINUXTYPE=targeted

或者临时关闭

[root@localhost ~]# setenforce 0

4、关闭防火墙

[root@localhost ~]# systemctl stop firewalld [root@localhost ~]# systemctl disable firewalld Removed symlink /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service. Removed symlink /etc/systemd/system/basic.target.wants/firewalld.service.

5、启动httpd服务,访问测试

[root@localhost ~]# systemctl start httpd

三、修改主配置文件

1、查看apache主配置文件,确保存在以下配置,因为等下需要在conf.d/创建虚机主机配置。

[root@localhost ~]# grep "conf.d" /etc/httpd/conf/httpd.conf

IncludeOptional conf.d/*.conf

2、另外,把 Require all denied默认拒绝访问设置为允许访问:Require all granted,方便测试。

[root@localhost ~]# vim /etc/httpd/conf/httpd.conf

四、新增虚拟主机配置文件
1、添加虚拟主机

1)创建配置文件

[root@localhost ~]# cd /etc/httpd/conf.d/ [root@localhost conf.d]# vim virtual.conf

3)创建虚机主机www的主页面

4)检查配置文件是否正常

[root@localhost conf.d]# httpd -t AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using localhost.localdomain. Set the 'ServerName' directive globally to suppress this message Syntax OK

5)重启httpd服务

[root@localhost conf.d]# systemctl restart httpd

6)打开浏览器,查看结果

2、配置基于IP+端口的虚拟主机

1)创建配置文件

[root@localhost ~]# cd /etc/httpd/conf.d/ [root@localhost conf.d]# vim virtual.conf

2)修改httpd主配置文件,在Listen 80下面添加一行监控8080端口

[root@localhost conf.d]# vim /etc/httpd/conf/httpd.conf

3)创建虚机主机a.com和b.com的主页面(如果前面已经创建就不用重复)

4)检查配置文件

[root@localhost conf.d]# httpd -t AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using localhost.localdomain. Set the 'ServerName' directive globally to suppress this message Syntax OK

5)重启httpd服务

[root@localhost conf.d]# systemctl restart httpd

6)打开浏览器,查看结果

3、基于域名的虚拟主机

1)创建配置文件

[root@localhost ~]# cd /etc/httpd/conf.d/ [root@localhost conf.d]# vim virtual.conf

2)修改物理主机hosts文件(C:\Windows\System32\drivers\etc),因为这里是因为物理机去访问Apache服务器

添加:

192.168.253.128 web.com

192.168.253.128 bbs.com

3)物理主机ping域名测试

4)检查配置文件

[root@localhost conf.d]# httpd -t AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using localhost.localdomain. Set the 'ServerName' directive globally to suppress this message Syntax OK

5)重启httpd服务

[root@localhost conf.d]# systemctl restart httpd

6)打开浏览器,查看结果

END

本文参与 腾讯云自媒体同步曝光计划,分享自微信公众号。
原始发表:2020-06-11,如有侵权请联系 cloudcommunity@tencent.com 删除
目录
  • 一、虚机主机的三种方式
  • 二、安装Apache
  • 三、修改主配置文件
  • 四、新增虚拟主机配置文件
    • 1、添加虚拟主机
    • 2、配置基于IP+端口的虚拟主机
    • 3、基于域名的虚拟主机
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档