如何用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. 九度OJ 1511 从尾到头打印链表

    题目地址:http://ac.jobdu.com/problem.php?pid=1511 题目描述: 输入一个链表,从尾到头打印链表每个节点的值. 输入: 每个输入文件仅包含一组测试样例. 每一组测 ...

  2. java集合——进度1

    集合类的由来:    对象用于封装特有数据,对象多了需要存储,如果对象的个数不确定.    就使用集合容器进行存储.    集合特点:1,用于存储对象的容器.2,集合的长度是可变的.3,集合中不可以存 ...

  3. [HttpClient]SSL双向实例

    package com.jerry.httpclient; import java.io.File; import java.io.FileInputStream; import java.secur ...

  4. js中的referrer返回上一页使用介绍

    js中的referrer的用法举例. js完整代码:  <script language="javascript">  var refer=document.refer ...

  5. web2py--------------用web2py写 django的例子 --------建立一个投票应用(2)

    建立模型 我们在models下及那里polls.py 文件内容如下 # -*- coding: utf-8 -*- pollsdb=DAL(uri='sqlite://polls.db') polls ...

  6. rman全备份异机恢复

    一.测试环境 [oracle@localhost ~]$ uname -a Linux localhost.localdomain -.el6.x86_64 # SMP Tue May :: EDT ...

  7. Tomcat安装与配置图文教程

    安装Tomcat之前先配置JDK,JDK的JAVA_HOME变量都必须设置好,以便Tomcat找到JDK.关闭防火墙等. 一:安装版Tomcat 1. 先下载tomcat,到http://tomcat ...

  8. uvision4 ide已停止工作

    情景描述: 笔者安装了新系统WIN8.1,装上了MDKV4.72.MDK编译程序可以正常工作,可是只要当我“下载程序”或者“调试程序”的时候就提示“uvision4 ide已停止工作”,迫不得已只能关 ...

  9. windows下使用eclipse调试C程序

    一.环境描述 Eclipse IDE for C/C++ Developers version 4.4.0 MinGW  gcc/g++ version 4.8.1;gdb version 7.6.1 ...

  10. SDC(7) -- 关于使能信号的时序放松

    先看下图: 假如使能信号的有效时间为时钟周期的2倍,此时需要使用 set_multicycle_path 放松使能信号 sel_xy_nab ,若是每个寄存器使能端都约束一遍,那就太麻烦了: 这时可以 ...