如何用Apache搭建的网站系统上运行多个站点呢?最平常的大概有3种方法。

第一种:单IP不同端口

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

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

下面简单来说这3种方法是如何配置的。

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.a.com
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.b.com
DocumentRoot "g:/www2"
<Directory "g:/www2">
Options FollowSymLinks
AllowOverride All
Require all granted
</Directory>
</VirtualHost>

Apache搭建多个站点的更多相关文章

  1. Apache搭建多个站点方法详解

    www.111cn.net 编辑:Bolshevik 来源:转载 Apache的虚拟主机是一种允许在同一台机器上配置多个不同站点的web服务器环境的,就是iis一样可以创建多站点了,但是apache需 ...

  2. apache 搭建PHP多站点

    修改apache 配置文件:httpd.conf 1.默认 Listen 80端口 2.添加配置如下: <VirtualHost *:80> ServerAdmin admin@yii.c ...

  3. 利用Wamp在本地搭建一个wordpress站点

    原文链接:利用Wamp在本地搭建一个wordpress站点 有时候我们会想搭建一个自己的站点,可是由于只是想自己访问,就不是很想为这个站点在买一个服务器和域名,那我们可能首先就想到把自己电脑当做服务器 ...

  4. Apache 多端口多站点配置实例

    分享下Apache多端口多站点的配置方法,配置apache服务器的朋友参考下. 配置httpd.conf 监听多个端口 复制代码代码如下: # Listen: Allows you to bind A ...

  5. 超详细动手搭建一个Vuepress站点及开启PWA与自动部署

    超详细动手搭建一个Vuepress站点及开启PWA与自动部署 五一之前就想写一篇关于Vuepress的文章,结果朋友结婚就不了了之了. 记得最后一定要看注意事项! Vuepress介绍 官网:http ...

  6. 教你phpstudy如何搭建本地多站点

    经常做多个网站同时开发,如何才能在本地能使部署多个站点,今天就来分享一下如何用PHPstudy搭建本地多站点. 点击上图中的 其它选项菜单 ,就会弹出下面的对话框,然后点击 站点域名管理 然后在 网站 ...

  7. 实战:使用SVN+apache搭建一个版本控制服务器

    今天讲的内容: 实战:使用SVN+apache搭建一个版本控制服务器 每天: 10:00 晚上:21:00 服务端:xuegod63.cn   IP:192.168.10.63 服务概述: SVN(s ...

  8. windows 配置 apache的多个站点

    windows 配置apache的多个站点 第一步打开apache的conf/extra/httpd-vhosts.conf,复制<VirtualHost></VirtualHost ...

  9. 手动搭建HTTP下载站点

    手动搭建HTTP下载站点 index.jsp <%--Listfile.jsp--%> <%@ page import="java.io.File,java.text.Si ...

随机推荐

  1. 第48条:如果需要精确的答案,请避免使用float和double

    float和double主要为了科学计算和工程计算而设计,执行二进制浮点运算,这是为了在广泛的数值范围上提供较为精确的快速近似计算而精心设计的.然而,它们没有提供完全精确的结果,所以不适合用于需要精确 ...

  2. php常用单词语法

    header("Content-type:text/html;charset=utf-8"); 加入数组array_push($ratings_store_cop,$value); ...

  3. 国内IT技术博客对比

    今天我想就自己对用了国内几个IT行业领先的博客做一个心得体会的总结: 我总共是用了三个,第一个是新浪,第二个是CSDN,第三个是博客园: 当然期间有自己搭建过wordpress,也用了一段时间,但是感 ...

  4. winfrom 多语言切换

    1.首先将窗体的“Localizable”属性置为“True”,然后将“Language”属性置为自己想要的语言,点击重新生成项目 例如:置为“中文”,以及“英文”.当每次置为不同的语言并重新生成项目 ...

  5. IIS 10.0 无法安装 URL rewrite重写模块 2.0

    打开注册表编辑器,在HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\InetStp位置 把MajorVersion的值改为9之后,就可以安装了,安装完成之后,再把Major ...

  6. MSSql ID自动增长删除数据重1开始

    dbcc checkident('db_Tome1.dbo.员工信息表',reseed,0) 注:dbcc checkident('表名',reseed,0)

  7. Oracle索引扫描

    Oracle索引扫描:先通过index查找到索引的值,并根据索引的值对应的rowid值(对于非唯一索引可能返回多个rowid值)直接从表中得到具体的数据.一个rowid唯一的表示一行数据,该行对应的数 ...

  8. Linux和Windows下查看环境变量方法对比

    摘自:Linux和Windows下查看环境变量方法对比 一.查看所有环境变量的名称和值 Linux下:export Windows下:set 二.根据名称查该环境变量的值 Linux下:echo $环 ...

  9. 一步步学习NHibernate(7)——HQL查询(1)

    请注明转载地址:http://www.cnblogs.com/arhat 从本章开始,老魏带着大家来学习一下HQL语句.HQL语句NHibernate为我们提供的一种功能比较强大的查询语句,这个HQL ...

  10. Mongodb使用总结

    学习Mongodb已经有半年多了,为啥学习它,工作需要啊.好了,废话不说,总结在实际项目应用中的几点问题. 学习总结 首先,mongodb基本上既照顾到了sql某些语法,又有nosql的许多优点.入门 ...