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 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)配置教程的更多相关文章
- apache 虚拟主机详细配置:http.conf配置详解
apache 虚拟主机详细配置:http.conf配置详解 Apache的配置文件http.conf参数含义详解 Apache的配置由httpd.conf文件配置,因此下面的配置指令都是在httpd. ...
- Apache虚拟主机的配置
虚拟主机的配置 基于IP地址的虚拟主机配置Listen 80DocumentRoot /www/example1ServerName www.example1.comDocumentRoot /www ...
- 【转】Apache虚拟主机的配置和泛解析域名的绑定
基于IP地址的虚拟主机配置 Listen 80 DocumentRoot /www/example1 ServerName www.example1.com DocumentRoot /www/exa ...
- Apache 虚拟主机 VirtualHost 配置
虚拟主机 (Virtual Host) 是在同一台机器搭建属于不同域名或者基于不同 IP 的多个网站服务的技术. 可以为运行在同一物理机器上的各个网站指配不同的 IP 和端口, 也可让多个网站拥有不同 ...
- Windows下Apache 虚拟主机 VirtualHost 配置
以下方式适合原生 Apache, XAMPP 和 WAMP 套件 1.修改Apache配置文件(httpd.conf),如下: # Virtual hostsInclude conf/extra/ht ...
- Apache虚拟主机&伪静态配置
Apache基本操作 安装:yum install httpd 启动:systemctl start httpd 查看进程:ps -ef | grep httpd 查看端口:sudo netstat ...
- apache 虚拟主机的配置
一.基于IP 1. 假设服务器有个IP地址为192.168.1.10,使用ifconfig在同一个网络接口eth0上绑定3个IP: [root@localhost root]# ifconfig et ...
- Nginx 虚拟主机 VirtualHost 配置
Nginx 是一个轻量级高性能的 Web 服务器, 并发处理能力强, 对资源消耗小, 无论是静态服务器还是小网站, Nginx 表现更加出色, 作为 Apache 的补充和替代使用率越来越高. 我在& ...
- 配置Apache虚拟主机
实验环境 一台最小化安装的CentOS 7.3虚拟机 配置基础环境 1. 安装apache yum install -y httpd 2. 建立虚拟主机的根目录 mkdir /var/wwwroot ...
随机推荐
- Sharepoint 2010 Workflow 发布
1.首先需要有一个已经创建好的WorkFlow 2.然后在Sharepoint中打开这个WorkFlow,点击Save as Template,系统会自动将这个Workflow保存在Site Asse ...
- grunt学习
有些时候,项目中的静态资源,比如图片占用的文件有点大,影响加载的速度,所以会选择grunt对其进行压缩打包.对于grunt其他的用法,还在继续学习中,先记录下关于grunt的一些学习. grunt是一 ...
- 巧妙使用checkbox制作纯css动态导航栏
前提:很多时候.我们的网页都需要一个垂直的导航栏.可以分类.有分类.自然就有展开.关闭的功能.你还在使用jquery操作dom来制作吗?那你就out了! 方案:使用checkbox 的 checked ...
- SQL技术内幕一
范式:关系模型的规范化规则. Codd提出的三个数据库范式: 1. 第一范式 第一范式要求表中的每一行都是必须是唯一的.因为关系型数据库是基于集合论的,而集合的定义中,要求每一个元素都是唯一的(在关系 ...
- 伪装隐藏Nginx,PHP版本号提升服务器安全性
可能有时候我们看某些站点想知道别人在使用什么版本的web服务器之类的信息时,却发现并未显示版本号,甚至连WEB服务器都有变化,可以通过以下 方法来隐藏Nginx.PHP的版本号信息,来提升一定的安全性 ...
- nuget的使用总结
使用NuGet发布自己的类库包(Library Package) from:http://blog.csdn.net/gulijiang2008/article/details/41724927 使用 ...
- 怎么预防sql注入攻击
假设sql是搜索用户A的文章,sql会是这样: select * from table where owner='A'; sql注入攻击者会修改用户名来实现攻击,例如把A 改成A' or 1='1 组 ...
- MVC-EditorFor与TextBoxFor的区别
EditorFor会根据后面提供的数据类型自动判断生成的控件类型(比如TextBox,CheckBox等): TextBoxFor生成的只是一个TextBox.
- Call Azure Queue get "The remote server returned an error: (400) Bad Request."
这几天开始研究Windows Azure, 在使用Azure Queue 的时候,CreateInfNotExists 总是抛出异常 "The remote server returned ...
- java基础知识整理:
一, Java中的继承: 1. final关键字(最终的,不可修改的不可变化的,可以修饰类,方法,变量等): 如果final修饰类的话,这个类不可以被继承: 如果修饰方法的话,这个方法不可以被子类覆盖 ...