使用apache来配置虚拟主机,在单一系统上运行多个网站。

现在很多linux主机使用apache作为web服务器的,大部分是基于这个原理来配置虚拟主机的。

下面就windows下以apache 2.4.3作为演示的一个教程。

这里只是简单的说明下,简述实现的原理

1.Apache的配置文件httpd.conf,找到Virtual hosts,进行如下修改保存。

# Virtual hosts
#Include conf/extra/httpd-vhosts.conf
去掉第2行的‘#’号,改为
# Virtual hosts
Include conf/extra/httpd-vhosts.conf

这样就开启了extra文件夹下的httpd-vhosts.conf,以后修改虚拟主机只要在这个文件进行。

2.对httpd-vhosts.conf进行配置。

例如域名www.a.com和www.b.com

# Virtual Hosts
#
# Required modules: mod_log_config # 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.4/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. #
# 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 *:80>
ServerAdmin webmaster@a.com
DocumentRoot "d:/www/a"
ServerName a.com
ServerAlias www.a.com
ErrorLog "logs/a.com.log"
CustomLog "logs/a.com.log" common
<Directory "d:/www/a">
Require all granted
</Directory>
</VirtualHost> <VirtualHost *:80>
ServerAdmin webmaster@b.com
DocumentRoot "d:/www/b"
ServerName b.com
ServerAlias www.b.com
ErrorLog "logs/b.com.log"
CustomLog "logs/b.com.log" common
<Directory "d:/www/b">
Require all granted
</Directory>
</VirtualHost>

注意:apache 2.4以上版本中需要在目录下面添加 Require all granted,否则无论怎么访问都是403。

这个我也查找了好久才查出的原因,官方文档也没有找到说明的地方。

Apache虚拟主机(vhost)配置教程的更多相关文章

  1. apache 虚拟主机详细配置:http.conf配置详解

    apache 虚拟主机详细配置:http.conf配置详解 Apache的配置文件http.conf参数含义详解 Apache的配置由httpd.conf文件配置,因此下面的配置指令都是在httpd. ...

  2. Apache虚拟主机的配置

    虚拟主机的配置 基于IP地址的虚拟主机配置Listen 80DocumentRoot /www/example1ServerName www.example1.comDocumentRoot /www ...

  3. 【转】Apache虚拟主机的配置和泛解析域名的绑定

    基于IP地址的虚拟主机配置 Listen 80 DocumentRoot /www/example1 ServerName www.example1.com DocumentRoot /www/exa ...

  4. Apache 虚拟主机 VirtualHost 配置

    虚拟主机 (Virtual Host) 是在同一台机器搭建属于不同域名或者基于不同 IP 的多个网站服务的技术. 可以为运行在同一物理机器上的各个网站指配不同的 IP 和端口, 也可让多个网站拥有不同 ...

  5. Windows下Apache 虚拟主机 VirtualHost 配置

    以下方式适合原生 Apache, XAMPP 和 WAMP 套件 1.修改Apache配置文件(httpd.conf),如下: # Virtual hostsInclude conf/extra/ht ...

  6. Apache虚拟主机&伪静态配置

    Apache基本操作 安装:yum install httpd 启动:systemctl start httpd 查看进程:ps -ef | grep httpd 查看端口:sudo netstat ...

  7. apache 虚拟主机的配置

    一.基于IP 1. 假设服务器有个IP地址为192.168.1.10,使用ifconfig在同一个网络接口eth0上绑定3个IP: [root@localhost root]# ifconfig et ...

  8. Nginx 虚拟主机 VirtualHost 配置

    Nginx 是一个轻量级高性能的 Web 服务器, 并发处理能力强, 对资源消耗小, 无论是静态服务器还是小网站, Nginx 表现更加出色, 作为 Apache 的补充和替代使用率越来越高. 我在& ...

  9. 配置Apache虚拟主机

    实验环境 一台最小化安装的CentOS 7.3虚拟机 配置基础环境 1. 安装apache yum install -y httpd 2. 建立虚拟主机的根目录 mkdir /var/wwwroot ...

随机推荐

  1. echshop 微信扫码支付 遇到的问题

    参考的网站 (转)http://www.ecshop119.com/ecshopjc-937.html(转)http://www.6gdown.com/softedupage/58929.html  ...

  2. js方法的命名不能使用表单元素的名称或ID

    今天在写页面的时候,遇到一个关于js方法的命名问题,先看下代码: 表单元素如下: <select name="isCulture" onchange="isCult ...

  3. npm:Node.js的软件包管理器

    npm https://www.npmjs.com/ 2016-08-03

  4. tar解压去除文件夹

    tar zxvf test.tar.gz  --strip-components 1 解压到当前目录,并去除一级目录

  5. DB天气app冲刺第四天

    今天卡壳了 做得很慢.. 明天继续 换一种思路试一下吧..

  6. POSIX多线程编程(上)-基本概念

    线程概念 我们把正在计算机中执行的程序叫做"进程"(Process) ,而不将其称为程序(Program).所谓"线程"(Thread),是"进程&q ...

  7. unity Android 打包后读取 xml 文件

    原地址:http://www.cnblogs.com/wuzhang/p/wuzhang20140731.html 问题:    前天在做东西的过程中发现了一个让人很纠结的问题,为什么Unity 程序 ...

  8. 用CURL来实现file_get_contents函数:curl_file_get_contents

    <?php $url='http://www.bamuyu.com/news/zixun/list_7_2.html'; $content=curl_file_get_contents($url ...

  9. php nl2br() 函数

    nl2br() 函数在字符串中的每个新行 (\n) 之前插入 HTML 换行符 (<br />).

  10. jar包中的类如何读取包内和包外的配置文件

    最近将代码打包成jar包,关于如何处理读取配置文件的问题特此记录一下. out.properties a.jar -com -a.class -in.properties 如上所示,out.prope ...