构建Apache虚拟主机(vhost)配置

使用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 hostsInclude 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 [email protected]    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 [email protected]    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。

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

时间: 2024-08-01 09:51:43

构建Apache虚拟主机(vhost)配置的相关文章

windows下apache虚拟主机的配置

我们这里主要讲最常用的基于域名的虚拟主机的配置. 1.记事本打开hosts文件,该文件在:C:\ Windows\ System32\ drivers\etc这个文件夹下, 在文件内容的末尾写入如下内容: [plain] view plain copy 127.0.0.1(不可改) www.fangchan.com(自定义) 2.记事本打开httpd.conf文件 ,该文件在apache的目录下,如: D:\AppServ\Apache2.2\conf,修改如下两处: [plain] view

Apache 虚拟主机 VirtualHost 配置

虚拟主机 (Virtual Host) 是在同一台机器搭建属于不同域名或者基于不同 IP 的多个网站服务的技术. 可以为运行在同一物理机器上的各个网站指配不同的 IP 和端口, 也可让多个网站拥有不同的域名. Apache 是世界上使用最广的 Web 服务器, 从 1.1 版开始支持虚拟主机. 本文将讲解在不同服务器 (Redhat Enterprise Linux, Ubuntu Linux, Windows) 上使用 Apache 搭建虚拟主机来搭建多个网站. Redhat Enterpri

apache 虚拟主机的配置

一.基于IP 1. 假设服务器有个IP地址为192.168.1.10,使用ifconfig在同一个网络接口eth0上绑定3个IP: [[email protected] root]# ifconfig eth0:1 192.168.1.11 [[email protected] root]# ifconfig eth0:2 192.168.1.12 [[email protected] root]# ifconfig eth0:3 192.168.1.13 2. 修改hosts文件,添加三个域名

php设置Apache虚拟主机vhost

本文地址:http://blog.csdn.net/oneym/article/details/48050487 作者:oneym 一.环境描述 1.使用php环境使用XAMPP 2.win7_64位系统 3.XAMPP安装在C盘根目录 二.修改相关文件 1.在系统中注册主机头 使用文本编辑工具编辑C:\Windows\System32\drivers\etc\hosts文件,在文件中添加一行记录如下所示: 127.0.0.1 oneym.dev 2.启用Apache的vhost功能 定位到C:

nginx配置虚拟主机vhost的方法详解

摘自:http://www.jb51.net/article/107331.htm Nginx vhost配置,可实现基于ip.端口号.servername的虚拟主机,同时可避免直接修改主配置文件.在nginx下配置虚拟主机vhost非常方便.这篇文章主要介绍了nginx配置虚拟主机vhost的方法,需要的朋友可以参考下 前言 所谓虚拟主机,是说通过几个不同的url地址,都能到达nginx环境,只不过针对不同的url,处理的逻辑不同.nginx支持虚拟主机,但是浏览器等客户端不知道,所以虚拟主机

Nginx 虚拟主机 VirtualHost 配置

Nginx 是一个轻量级高性能的 Web 服务器, 并发处理能力强, 对资源消耗小, 无论是静态服务器还是小网站, Nginx 表现更加出色, 作为 Apache 的补充和替代使用率越来越高. 我在<Apache 虚拟主机 VirtualHost 配置>介绍了在不同操作系统上使用 Apahce 虚拟主机的方法, 还有那么些朋友想知道 Nginx 虚拟主机配置方法, 本文作为补充也介绍如何 Nginx 上添加虚拟主机. 绝大多数的 Nginx 运行在 Linux 机器上, 虽然有 Windows

IP、Apache虚拟主机配置部分学习笔记

IP地址 IP地址就是计算机的一个"编号",该编号是唯一的.相当于我们的身份证号码一样. IP地址格式:a.b.c.d  ,每一段的取值范围0-255. 本机的IP地址:127.0.0.1      只能是自己访问自己,别人无法通过这个IP访问你的电脑. 本机的域名:localhost         只能是自己访问自己,别人无法通过这个域名来访问你的电脑. 别人要想访问你的电脑,必须通过网卡的IP地址来访问. nslookup  www.baidu.com  命令窗口查看域名对应得I

Apache虚拟主机配置

在一个Apache服务器上可以配置多个虚拟主机,实现一个服务器提供多站点服务,其实就是访问同一个服务器上的不同目录.Apache虚拟主机配置有3中方法:基于IP配置.基于域名配置和基于端口配置,这里介绍基于域名配置和基于端口配置,基于IP配置方法类似. 1. Apache基于域名配置虚拟主机: 打开Apache安装目录下的配置文件conf/extra/httpd-vhosts.conf,添加如下配置信息: <VirtualHost _default_:80> DocumentRoot &quo

Apache虚拟主机及别名配置

Apache虚拟主机配置 增加监听端口(修改conf/httpd.conf文件) Listen 127.0.0.1:8092 修改主站点权限(修改conf/httpd.conf文件) <Directory /> AllowOverride none # Require all denied </Directory> 允许虚拟主机配置(修改conf/httpd.conf文件) # Virtual hosts Include conf/extra/httpd-vhosts.conf 增