www.111cn.net 编辑:Bolshevik 来源:转载
Apache的虚拟主机是一种允许在同一台机器上配置多个不同站点的web服务器环境的,就是iis一样可以创建多站点了,但是apache需要在编辑状态操作,不能像windows iis直接点击几下就好了,下面我来给各位介绍配置方法。

最平常的大概有3种方法。

第一种:单IP不同端口

第二种:多IP同端口(独立IP的虚拟空间)

第三种:域名绑定根目录的方式(共享IP的虚拟空间)

Apache的核心配置文件名是”httpd.conf”,其所存放的路径在Apache目录下的conf文件夹下。修改它只需要使用记事本(建议使用其他编辑器,带行数的那种,方便修改),生效的话只需要保存httpd.conf,重启apache即可。

下面多站点支持的话,修改httpd.conf的第187~264行(不同的httpd.conf可能有差异),也就是在ServerAdmin和ServerName那里,大部分是注释。下面是主要修改的地方。

注意:如果是服务器请备份httpd.conf后再修改文件。

 代码如下 复制代码

# 'Main' server configuration
#
# The directives in this section set up the values used by the 'main'
# server, which responds to any requests that aren't handled by a
# <VirtualHost> definition.  These values also provide defaults for
# any <VirtualHost> containers you may define later in the file.
#
# All of these directives may appear inside <VirtualHost> containers,
# in which case these default settings will be overridden for the
# virtual host being defined.
#

#
# ServerAdmin: Your address, where problems with the server should be
# e-mailed.  This address appears on some server-generated pages, such
# as error documents.  e.g. admin@your-domain.com
#
ServerAdmin admin@example.com

#
# ServerName gives the name and port that the server uses to identify itself.
# This can often be determined automatically, but we recommend you specify
# it explicitly to prevent problems during startup.
#
# If your host doesn't have a registered DNS name, enter its IP address here.
#
ServerName www.example.com:80

#
# Deny access to the entirety of your server's filesystem. You must
# explicitly permit access to web content directories in other 
# <Directory> blocks below.
#
<Directory />
    AllowOverride All
    Require all denied
</Directory>

#
# Note that from this point forward you must specifically allow
# particular features to be enabled - so if something's not working as
# you might expect, make sure that you have specifically enabled it
# below.
#

#
# DocumentRoot: The directory out of which you will serve your
# documents. By default, all requests are taken from this directory, but
# symbolic links and aliases may be used to point to other locations.
#
DocumentRoot "g:/www"
<Directory "g:/www">
    #
    # Possible values for the Options directive are "None", "All",
    # or any combination of:
    #   Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews
    #
    # Note that "MultiViews" must be named *explicitly* --- "Options All"
    # doesn't give it to you.
    #
    # The Options directive is both complicated and important.  Please see
    # http://httpd.apache.org/docs/2.4/mod/core.html#options
    # for more information.
    #
    Options Indexes FollowSymLinks

#
    # AllowOverride controls what directives may be placed in .htaccess files.
    # It can be "All", "None", or any combination of the keywords:
    #   Options FileInfo AuthConfig Limit
    #
    AllowOverride All

#
    # Controls who can get stuff from this server.
    #
    Require all granted
</Directory>

第一种一般是测试环境,毕竟加了端口,如何绑定域名,访问的时候域名后面也需加端口。

例子分别通过80和8080访问不同的根目录。

大概在50几行有个Listen 80,在下面添加8080端口。

 代码如下 复制代码

Listen 80
Listen 8080<VirtualHost *:80> 
    ServerAdmin admin@myxzy.com 
    ServerName localhost:80 
    DocumentRoot "g:/www1" 
     <Directory "g:/www1"> 
     Options  Indexes FollowSymLinks 
     AllowOverride All 
     Require all granted 
   </Directory>   
</VirtualHost> 
<VirtualHost *:8080> 
    ServerAdmin admin@myxzy.com
    ServerName localhost:8080  
    DocumentRoot "g:/www2" 
   <Directory "g:/www2"> 
     Options Indexes FollowSymLinks 
     AllowOverride All 
     Require all granted 
   </Directory>       
</VirtualHost>

第二种多IP同端口。

IP地址1:192.168.2.2

IP地址2:192.168.1.68

端口同是80端口。

 代码如下 复制代码

<VirtualHost 192.168.1.68:80> 
    ServerAdmin admin@myxzy.com 
    ServerName localhost:80 
    DocumentRoot "g:/www1" 
     <Directory "g:/www1"> 
     Options FollowSymLinks 
     AllowOverride All 
     Require all granted 
   </Directory>   
</VirtualHost> 
<VirtualHost 192.168.2.2:80> 
    ServerAdmin admin@myxzy.com
    ServerName localhost:80 
    DocumentRoot "g:/www2" 
   <Directory "g:/www2"> 
     Options FollowSymLinks 
     AllowOverride All 
     Require all granted 
   </Directory>       
</VirtualHost>

第三种同IP不同域名和根目录(域名的话修改本地host演示)。

 代码如下 复制代码

<VirtualHost 192.168.2.2:80> 
    ServerAdmin admin@myxzy.com 
    ServerName www.111cn.net 
    DocumentRoot "g:/www1" 
     <Directory "g:/www1"> 
     Options FollowSymLinks 
     AllowOverride All 
     Require all granted 
   </Directory>   
</VirtualHost> 
<VirtualHost 192.168.2.2:80> 
    ServerAdmin admin@myxzy.com
    ServerName www.111cn.net
    DocumentRoot "g:/www2" 
   <Directory "g:/www2"> 
     Options FollowSymLinks 
     AllowOverride All 
     Require all granted 
   </Directory>       
</VirtualHost>

Apache搭建多个站点方法详解的更多相关文章

  1. Wordpress 网站搭建及性能监控方法详解!

    前言 说到 Wordpress,大家往往想到的是博客,其实,如今的 WordPress 已经成为全球使用量最多的开源 CMS 系统.并且,如果你有一定的技术基础稍加改动,就可以搭建出新闻网站.企业网站 ...

  2. nginx搭建流媒体服务器的方法详解

      一.FLV视频发布方式简介 FLV视频有两总发布方式 1.  HTTP方式 这种方式要下载FLV视频文件到本地播放,一旦FLV视频文件下载完成,就不会消耗服务器的资源和带宽,但是拖动功能没有RTM ...

  3. Windows下Nginx Virtual Host多站点配置详解

    Windows下Nginx Virtual Host多站点配置详解 此教程适用于Windows系统已经配置好Nginx+Php+Mysql环境的同学. 如果您还未搭建WNMP环境,请查看 window ...

  4. robots.txt文件配置和使用方法详解

    robots.txt文件,提起这个概念,可能不少站长还很陌生:什么是robots.txt文件?robots.txt文件有什么作用?如何配置robots.txt文件?如何正确使用robots.txt文件 ...

  5. asp.net iis URLRewrite 实现方法详解

    原文 asp.net iis URLRewrite 实现方法详解 实现非常简单首先你要在你的项目里引用两个dll:actionlessform.dll.urlrewriter.dll,真正实现重写的是 ...

  6. PHP cURL实现模拟登录与采集使用方法详解教程

    来源:http://www.zjmainstay.cn/php-curl 本文将通过案例,整合浏览器工具与PHP程序,教你如何让数据 唾手可得 . 对于做过数据采集的人来说,cURL一定不会陌生.虽然 ...

  7. MP实战系列(十一)之封装方法详解(续一)

    之前写的封装方法详解,比较简要. 今天我主要讲增加和删除及其修改.查的话得单独再详讲. 增删改查,无论是Java或者C#等等,凡是对数据库操作的都离不开这四个. 一.增加方法讲解 MyBatis Pl ...

  8. python中requests库使用方法详解

    目录 python中requests库使用方法详解 官方文档 什么是Requests 安装Requests库 基本的GET请求 带参数的GET请求 解析json 添加headers 基本POST请求 ...

  9. Windows系统启动iis方法详解

    很多网友一般都用Windows 系统自带的iis服务器来配置web网站,在本地进行调试和修改后才正式上线.虽说操作不难,但是小白来说却无从下手,很多人根本不知道iss在哪,怎么启动,更谈不上配置或者其 ...

随机推荐

  1. 简单分析Java的HashMap.entrySet()的实现

    关于Java的HashMap.entrySet(),文档是这样描述的:这个方法返回一个Set,这个Set是HashMap的视图,对Map的操作会在Set上反映出来,反过来也是.原文是 Returns ...

  2. Jquery.Page.js 分页插件的使用

    1.简单直接贴代码 需要引用以下样式和脚本 <link href="~/Scripts/Page/pager.css" rel="stylesheet" ...

  3. C#拉姆达(=>)表达式

    前言: 之前小猪曾经分享过自己对C#委托的一点理解 其实在使用委托的过程中我们会大量的使用拉姆达(=>)表达式 介绍: "Lambda表达式"是一个匿名函数,是一种高效的类似 ...

  4. 安卓/res/menu/的使用

    <?xml version="1.0" encoding="utf-8"?> <menu xmlns:android="http:/ ...

  5. InLineHookSSDT

    //当Ring3调用OpenProcess //1从自己的模块(.exe)的导入表中取值 //2Ntdll.dll模块的导出表中执行ZwOpenProcess(取索引 进入Ring0层) //3进入R ...

  6. socket.io遇到的问题

    一.socket.io指定客户端html文件所用到的sendFile()方法中的文件路径必须是绝对路径,而且要符合一定规则: app.get('/',function(req,res){ res.se ...

  7. sqlite3 SQL常用语句

    1. select SELECT LastName,FirstName FROM Persons; SELECT * FROM Persons; 2. where SELECT * FROM Pers ...

  8. IT公司100题-1-二叉树转换为双链表

    问题描述: 输入一棵二元查找树,将该二元查找树转换成一个排序的双向链表.要求不能创建任何新的结点,只调整指针的指向. 10   /   \  6      14/  \    /   \4   8 1 ...

  9. MyEclipse取消验证Js的两种方法

    MyEclipse取消验证Js的两种方法 作者: 字体:[增加 减小] 类型:转载 通过js写一个web工程的相关页面时感觉很卡,修改内存也不行下面有两种解决方法,大家可以尝试下 前言:有时我们通过j ...

  10. [转]centos7 配置yum源(本地+光盘)

    from:http://wangyan.org/blog/setup-local-yum-repo.html 一,本地 1.创建本地yum仓库 1.mkdir -p /yum/local #可以有N级 ...