虚拟主机:部署多个站点,每个站点,希望用不同的域名和站点目录,或者是不同的端口,不同的ip,需要虚拟主机功能。一句话,一个http服务要配置多个站点,就需要虚拟主机。

虚拟主机分类:基于域名、基于端口、基于ip;所谓的基于**,就是靠**来区分不同的站点,支持各种混合,N多个虚拟主机。

基于域名的虚拟主机配置如下:

创建环境:

站点目录 域名
/var/html/blog blog.bqh123.com
/var/html/bbs bbs.bqh123.com
[root@bqh- extra]# mkdir /var/html/{blog,bbs} -p
[root@bqh- extra]# touch /var/html/{blog,bbs}/index.html
[root@bqh- extra]# tree /var/html/
/var/html/
├── bbs
│ └── index.html
└── blog
└── index.html directories, files
[root@bqh- extra]# for name in blog bbs;do echo "http://$name.bqh123.com" >/var/html/$name/index.html;done
[root@bqh- extra]# for name in blog bbs;do cat /var/html/$name/index.html;done
http://blog.bqh123.com
http://bbs.bqh123.com

配置虚拟主机配置文件:httpd-vhosts.conf

[root@bqh- extra]# vim httpd-vhosts.conf

   #
# Virtual Hosts
#
# If you want to maintain multiple domains/hostnames on your
# machine you can setup VirtualHost containers for them. Most configurations
# use only name-based virtual hosts so the server doesn't need to worry about
# IP addresses. This is indicated by the asterisks in the directives below.
#
# Please see the documentation at
# <URL:http://httpd.apache.org/docs/2.2/vhosts/>
# for further details before you try to setup virtual hosts.
#
# You may use the command line option '-S' to verify your virtual host
# configuration. #
# Use name-based virtual hosting.
#
NameVirtualHost *: #
# VirtualHost example:
# Almost any Apache directive may go into a VirtualHost container.
# The first VirtualHost section is used for all requests that do not
# match a ServerName or ServerAlias in any <VirtualHost> block.
#
<VirtualHost *:>
ServerAdmin @qq.com
DocumentRoot "/var/html/blog"
ServerName blog.bqh123.com
ServerAlias bg.bqh123.com
ErrorLog "logs/blog-error_log"
CustomLog "logs/blog-access_log" common
</VirtualHost> <VirtualHost *:>
ServerAdmin @qq.com
DocumentRoot "/var/html/bbs"
ServerName bbs.bqh123.com
ServerAlias bs.bqh123.com
ErrorLog "logs/bbs-error_log"
CustomLog "logs/bbs-access_log" common
/VirtualHost>

 在主配置文件(httpd.conf)里激活生效:

  • Include conf/extra/httpd-vhosts.conf
  • Include conf/extra/httpd-mpm.conf

检测配置文件语法错误并刷新配置:

[root@bqh- extra]# ../../bin/apachectl -t
httpd: apr_sockaddr_info_get() failed for bqh-
httpd: Could not reliably determine the server's fully qualified domain name, using 127.0.0.1 for ServerName
Syntax OK
[root@bqh- extra]# ../../bin/apachectl graceful
httpd: apr_sockaddr_info_get() failed for bqh-
httpd: Could not reliably determine the server's fully qualified domain name, using 127.0.0.1 for ServerName

配置一下hosts解析:

[root@bqh- extra]# cat /etc/hosts
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
:: localhost localhost.localdomain localhost6 localhost6.localdomain6 192.168.0.119 blog.bqh123.com bbs.bqh123.com

windows系统,在“C:\Windows\System32\drivers\etc”下的hosts中配置一下域名解析:

----------------------------------------------------------------------------------

用cur或客户端浏览器测试一下:

解决方法:

在主配置文件(httpd.conf)追加一下内容:

  <Directory "/var/html">
Options FollowSymLinks
AllowOverride None
Order allow,deny
Allow from all
</Directory>

检测配置文件语法错误,刷新配置,从新启动:

[root@bqh- conf]# vim httpd.conf
[root@bqh- conf]# ../bin/apachectl -t
httpd: apr_sockaddr_info_get() failed for bqh-
httpd: Could not reliably determine the server's fully qualified domain name, using 127.0.0.1 for ServerName
Syntax OK
[root@bqh- conf]# ../bin/apachectl graceful
httpd: apr_sockaddr_info_get() failed for bqh-
httpd: Could not reliably determine the server's fully qualified domain name, using 127.0.0.1 for ServerName

用cur或客户端浏览器测试一下:

---------------------------------------------------------------------------------

ok,Apache基于域名的虚拟主机配置及测试完成。

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

基于端口的虚拟主机配置如下:

①在主配置文件httpd.conf里配置监听新增端口:

②在虚拟机配置文件httpd-vhosts.conf修改如下:

③检测配置文件语法错误,刷新配置,从新启动:

[root@bqh- conf]# ../bin/apachectl -t
httpd: apr_sockaddr_info_get() failed for bqh-
httpd: Could not reliably determine the server's fully qualified domain name, using 127.0.0.1 for ServerName
Syntax OK
[root@bqh- conf]# ../bin/apachectl graceful
httpd: apr_sockaddr_info_get() failed for bqh-
httpd: Could not reliably determine the server's fully qualified domain name, using 127.0.0.1 for ServerName
[root@bqh- conf]# netstat -lntup|egrep "80|90"
tcp ::: :::* LISTEN /httpd
tcp ::: :::* LISTEN /httpd

④用cur或客户端浏览器测试一下:

注:如果不加端口访问,默认以ip的形式解析访问。

ok,Apache基于端口的虚拟主机配置及测试完成。

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

基于IP的虚拟主机配置如下:

①添加别名IP

②在虚拟机配置文件httpd-vhosts.conf修改如下:

③检测配置文件语法错误,刷新配置,从新启动:

④用cur或客户端浏览器测试一下:

ok,Apache基于IP的虚拟主机配置及测试完成

Apache基于域名、端口、IP的虚拟主机配置(Centos 6.5)的更多相关文章

  1. CentOS 7运维管理笔记(6)----Apache 基于 IP 的虚拟主机配置

    Apache 配置虚拟主机支持3种方式:基于IP的虚拟主机配置,基于端口的虚拟主机配置,基于域名的虚拟主机配置.本篇随笔记录自己基于IP的虚拟主机配置. 如果同一台服务器有多个IP,可以使用基于IP的 ...

  2. Nginx总结(二)基于ip的虚拟主机配置

    前面讲了如何安装配置Nginx,大家可以去这里看看nginx系列文章:https://www.cnblogs.com/zhangweizhong/category/1529997.html 今天要说的 ...

  3. 源码编译安装LAMP环境及配置基于域名访问的多虚拟主机

    实验环境及软件版本: CentOS版本: 6.6(2.6.32.-504.el6.x86_64) apache版本: apache2.2.27 mysql版本:  Mysql-5.6.23 php版本 ...

  4. 源码编译安装LNMP环境及配置基于域名访问的多虚拟主机

    实验环境及软件版本: CentOS版本: 6.6(2.6.32.-504.el6.x86_64) nginx版本: nginx-1.6.2 mysql版本:  Mysql-5.6.23 php版本: ...

  5. mac 下 xampp 多域名 多站点 多虚拟主机 配置

    前言:最近用mac工作了,需要搭建个调试前段程序的站点,选了xampp,需求是能同时运行多个站点,多个域名,目录自定义,网上找了好多资料,都感觉有些不符合心意,且复制文确实很多,甚至有些没实践过的在乱 ...

  6. 基于ip的虚拟主机配置——在一台服务器上绑定多个 IP 地址

    进入/etc/sysconfig/network-scripts,修改ifcfg-ens33文件 输入 ip addr 查看ip 引用:https://blog.csdn.net/u013887008 ...

  7. 【 APACHE 】 Apache2.4.x版本虚拟主机配置

    今天准备使用apache搭建一个目录浏览的服务,折腾了一下. apache2.4.x以后的版本: Require all granted 代替了apache2.4.x以前版本: Order Allow ...

  8. lamp centos虚拟主机配置

    1.基于不同端口的虚拟主机配置 [root@lamp~]# vi /etc/httpd/conf/httpd.conf Listen 80      #设置监听不同的虚拟主机需要使用的端口 Liste ...

  9. Nginx配置基于多域名、端口、IP的虚拟主机

    原文:https://www.cnblogs.com/ssgeek/p/9220922.html ------------------------------- Nginx配置基于多域名.端口.IP的 ...

随机推荐

  1. RabbitMQ 清除全部队列及消息

    前言 安装RabbitMQ后可访问:http://{rabbitmq安装IP}:15672使用(默认的是帐号guest,密码guest.此账号只能在安装RabbitMQ的机器上登录,无法远程访问登录. ...

  2. Bmp格式图片与16进制的互相转换简解 Python

    BMP TO HEX 首先介绍Github上一个简单的Bmp转成16进制的py: https://github.com/robertgallup/bmp2hex 网上这种例子很多.思路也简单:将bmp ...

  3. mssqlserver修改表名,列名,添加表列,删除表列,修改表列类型

    mssqlserver修改表名,列名,添加表列,删除表列,修改表列类型 ,代码肯定省事的呀 --添加表列 alter table test ) null; --删除表列 alter table tes ...

  4. jqweui Popup 使用说明

    使用步骤说明: 今天遇到一个问题,无论怎么点击一个图标都不会弹出对应的遮罩层,但是把示列代码拷贝过来又可以正常显示:结果是由于在复制的时候把 # 号弄掉了 错误操作展示: <a href=&qu ...

  5. 牛掰的socat工具介绍

    Socat 是 Linux 下的一个多功能的网络工具,名字来由是 「Socket CAT」.其功能与有瑞士军刀之称的 Netcat(nc) 类似,可以看做是 Netcat 的加强版.Socat 的主要 ...

  6. bootstrap-table:操作栏点击编辑按钮弹出模态框修改数据

    核心代码: columns: [ { checkbox:true //第一列显示复选框 }, ... { field: 'fail_num', title: '失败数' }, { field: 'op ...

  7. 什么时候该用readfile() , fread(), file_get_contents(), fgets()?

    fread() 和 readfile() fread() 最大一次性能读取 8k长度的字节数,所以不能一次性读取大文件去作下载. 优势在于,操作更加灵活,每次读取指定字节的内容,用于下载时方便控制服务 ...

  8. AWS 数据库(七)

    数据库概念 关系型数据库 关系数据库提供了一个通用接口,使用户可以使用使用 编写的命令或查询从数据库读取和写入数据. 关系数据库由一个或多个表格组成,表格由与电子表格相似的列和行组成. 以行列形式存储 ...

  9. SQL命令如何分发到集群的各节点

    有些数据库集群的规模是很大的,有上百个节点,那么维护SQL命令如何快速分发给各个节点,例如:要加个字段,逐个节点操作那是十分低效,枯燥的. TreeSoft增加了[SQL分发]功能,简单配置,可以快速 ...

  10. CF1223D Sequence Sorting

    思路: 首先把数组离散化,然后观察可以发现,在最优解中最终没有被移动过的那些数字一定是连续的,那么找到最长的连续的数字长度即可. 实现: #include <bits/stdc++.h> ...