网创优客建站品牌官网
为成都网站建设公司企业提供高品质网站建设
热线:028-86922220
成都专业网站建设公司

定制建站费用3500元

符合中小企业对网站设计、功能常规化式的企业展示型网站建设

成都品牌网站建设

品牌网站建设费用6000元

本套餐主要针对企业品牌型网站、中高端设计、前端互动体验...

成都商城网站建设

商城网站建设费用8000元

商城网站建设因基本功能的需求不同费用上面也有很大的差别...

成都微信网站建设

手机微信网站建站3000元

手机微信网站开发、微信官网、微信商城网站...

建站知识

当前位置:首页 > 建站知识

CentOS7配置httpd虚拟主机教程

本实验旨在CentOS7系统中,httpd-2.4配置两台虚拟主机,主要有以下要求:

10年的张掖网站建设经验,针对设计、前端、开发、售后、文案、推广等六对一服务,响应快,48小时及时工作处理。成都营销网站建设的优势是能够根据用户设备显示端的尺寸不同,自动调整张掖建站的显示方式,使网站能够适用不同显示终端,在浏览器中调整网站的宽度,无论在任何一种浏览器上浏览网站,都能展现优雅布局与设计,从而大程度地提升浏览体验。成都创新互联公司从事“张掖网站设计”,“张掖网站推广”以来,每个客户项目都认真落实执行。

(1) 提供两个基于名称的虚拟主机:

www1.stuX.com,页面文件目录为/web/vhosts/www1;错误日志为/var/log/httpd/www1/error_log,访问日志为/var/log/httpd/www1/access_log;
  www2.stuX.com,页面文件目录为/web/vhosts/www2;错误日志为/var/log/httpd/www2/error_log,访问日志为/var/log/httpd/www2/access_log;

(2) 通过www1.stuX.com/server-status输出其状态信息,且要求只允许提供账号的用户访问;

(3) www1不允许192.168.1.0/24网络中的主机访问; 

查看系统版本和httpd版本

[root@host ~]$httpd -v
Server version: Apache/2.4.6 (CentOS)
Server built:  Nov 14 2016 18:04:44
[root@host ~]$cat /etc/centos-release
CentOS Linux release 7.3.1611 (Core) 

启动httpd,测试能否正常运行

[root@host ~]$systemctl start httpd.service 
[root@host ~]$systemctl status httpd.service 
● httpd.service - The Apache HTTP Server
  Loaded: loaded (/usr/lib/systemd/system/httpd.service; enabled; vendor preset: disabled)
  Active: active (running) since Thu 2017-06-01 03:03:12 CST; 5s ago           #  active 表示正常运行
   Docs: man:httpd(8)
      man:apachectl(8)
 Process: 6473 ExecStop=/bin/kill -WINCH ${MAINPID} (code=exited, status=0/SUCCESS)
 Main PID: 6485 (httpd)
  Status: "Processing requests..."
  CGroup: /system.slice/httpd.service
      ├─6485 /usr/sbin/httpd -DFOREGROUND
      ├─6486 /usr/sbin/httpd -DFOREGROUND
      ├─6487 /usr/sbin/httpd -DFOREGROUND
      ├─6489 /usr/sbin/httpd -DFOREGROUND
      ├─6490 /usr/sbin/httpd -DFOREGROUND
      └─6572 /usr/sbin/httpd -DFOREGROUND

Jun 01 03:03:11 host systemd[1]: Starting The Apache HTTP Server...
Jun 01 03:03:12 host systemd[1]: Started The Apache HTTP Server.

使用curl命令访问

[root@host ~]$ip a show ens38  # 查看ip 
3: ens38:  mtu 1500 qdisc pfifo_fast state UP qlen 1000
  link/ether 00:0c:29:dc:18:5f brd ff:ff:ff:ff:ff:ff
  inet 192.168.55.128/24 brd 192.168.55.255 scope global dynamic ens38
    valid_lft 1752sec preferred_lft 1752sec
  inet6 fe80::20c:29ff:fedc:185f/64 scope link 
    valid_lft forever preferred_lft forever
[root@host ~]$curl http://192.168.55.128    # 访问

CentOS 7.3

创建指定文件目录

[root@host conf.d]$mkdir -pv /web/vhosts/www1
[root@host conf.d]$mkdir -pv /web/vhosts/www2
[root@host conf.d]$mkdir -pv /var/log/httpd/www2
[root@host conf.d]$mkdir -pv /var/log/httpd/www1

根据要求填写虚拟主机配置信息

# path /etc/httpd/conf.d/vir.conf   # 配置文件全路径
#virtual host 1    # 虚拟主机1的配置

  ErrorLog "/var/log/httpd/www1/error_log"
  CustomLog "/var/log/httpd/www1/access_log" combined
  
    SetHandler server-status
  
  
    
    Require all granted
    Require not ip 192.168.1
    
  

# virtual host 2   # 虚拟主机2的配置

  ServerName www2.stuX.com
  DocumentRoot "/web/vhosts/www2"
  ErrorLog "/var/log/httpd/www2/error_log"
  CustomLog "/var/log/httpd/www2/access_log" combined
  
    
      Require all granted
    
  

创建www1和www2的index页面

[root@host conf.d]$cat /web/vhosts/www1/index.html
welcome to www1
thank you
[root@host conf.d]$cat /web/vhosts/www2/index.html 
welcome to www2
thank you

重载httpd配置文件

[root@host conf.d]$httpd -t
Syntax OK
[root@host conf.d]$systemctl reload httpd.service 

 修改客户端主机的hosts文件,以便能解析域名

hosts在windows环境下的路径为C:\Windows\System32\drivers\etc。在该文件中添加两行

192.168.55.128 www1.stuX.com
192.168.55.128 www2.stuX.com

访问结果

CentOS7配置httpd虚拟主机教程

图1、访问www1站点

CentOS7配置httpd虚拟主机教程

图2、访问www2站点

CentOS7配置httpd虚拟主机教程

图3、查看www1站点的访问状态——正常

CentOS7配置httpd虚拟主机教程

图4、查看www2站点的访问状态错误

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持创新互联。


网站题目:CentOS7配置httpd虚拟主机教程
标题来源:http://bjjierui.cn/article/ggijid.html

其他资讯