配置Apache虚拟主机
[title]: # 配置Apache虚拟主机
实验环境
- 一台最小化安装的CentOS 7.3虚拟机
配置基础环境
1. 安装apache
yum install -y httpd
2. 建立虚拟主机的根目录
mkdir /var/wwwroot
mkdir /var/wwwroot/site1
mkdir /var/wwwroot/site2
echo -e "site1" >> /var/wwwroot/site1/index.html
echo -e "site2" >> /var/wwwroot/site2/index.html

3. 关闭CentOS的防火墙
setenforce 0
systemctl stop firewalld
systemctl disable firewalld

配置基于端口的虚拟主机
1. 编辑apache配置文件
vim /etc/httpd/conf.d/vhost.conf
2. 添加以下内容
Listen 8081
<VirtualHost *:8081>
DocumentRoot "/var/wwwroot/site1"
ErrorLog "logs/site1.error.log"
CustomLog "logs/site1.access.log" common
<Directory "/var/wwwroot/site1">
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Require all granted
</Directory>
</VirtualHost>
Listen 8082
<VirtualHost *:8082>
DocumentRoot "/var/wwwroot/site2"
ErrorLog "logs/site2.error.log"
CustomLog "logs/site2.access.log" common
<Directory "/var/wwwroot/site2">
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Require all granted
</Directory>
</VirtualHost>

3. 启动apache服务
systemctl start httpd
4. 在宿主机访问两个站点
http://192.168.204.133:8081
http://192.168.204.133:8082


配置基于域名的虚拟主机
1. 编辑apache配置文件
vim /etc/httpd/conf.d/vhost.conf
2. 修改为以下内容
<VirtualHost *:80>
DocumentRoot "/var/wwwroot/site1"
ServerName site1.test.com
ErrorLog "logs/site1.error.log"
CustomLog "logs/site1.access.log" common
<Directory "/var/wwwroot/site1">
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Require all granted
</Directory>
</VirtualHost>
<VirtualHost *:80>
DocumentRoot "/var/wwwroot/site2"
ServerName site2.test.com
ErrorLog "logs/site2.error.log"
CustomLog "logs/site2.access.log" common
<Directory "/var/wwwroot/site2">
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Require all granted
</Directory>
</VirtualHost>

3. 重启apache服务
systemctl restart httpd
4. 在Windows上修改hosts文件
编辑C:\Windows\System32\drivers\etc\hosts文件,
添加以下内容(根据实际情况自己修改)
192.168.204.135 site1.test.com
192.168.204.135 site2.test.com
5. 在宿主机访问两个站点
http://site1.test.com/
http://site2.test.com/


配置基于IP的虚拟主机
1. 在虚拟机上增加两个IP地址
ifconfig ens33:1 192.168.204.135
ifconfig ens33:2 192.168.204.136

2. 重新编辑apache配置文件
vim /etc/httpd/conf.d/vhost.conf
3. 修改配置文件为以下内容
<VirtualHost 192.168.204.135:80>
DocumentRoot "/var/wwwroot/site1"
ErrorLog "logs/site1.error.log"
CustomLog "logs/site1.access.log" common
<Directory "/var/wwwroot/site1">
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Require all granted
</Directory>
</VirtualHost>
<VirtualHost 192.168.204.136:80>
DocumentRoot "/var/wwwroot/site2"
ErrorLog "logs/site2.error.log"
CustomLog "logs/site2.access.log" common
<Directory "/var/wwwroot/site2">
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Require all granted
</Directory>
</VirtualHost>

4. 重启apache服务
systemctl restart httpd
5. 在宿主机访问两个站点
http://192.168.204.135/
http://192.168.204.136/


本文链接:https://www.cnblogs.com/connect/p/apache-vhost.html
配置Apache虚拟主机的更多相关文章
- wamp开发环境配置之配置Apache虚拟主机
网站建设人员在本地测试时,常常不是一个网站,那怎么能像输入域名一样在地址栏上面输入“域名”就能本地访问该网站呢?这里就要配置Apache虚拟主机了! 1.找到apache\conf\httpd.con ...
- 配置LANMP环境(7)-- 配置nginx反向代理,与配置apache虚拟主机
一.配置nginx反向代理 1.修改配置文件 vim /etc/nginx/nginx.conf 在35行http下添加一下内容: include /data/nginx/vhosts/*.conf; ...
- 配置apache虚拟主机的实例总结
如何实现apache虚拟主机配置. 1.基于ip地址的虚拟主机Listen 80<VirtualHost 172.20.30.40> DocumentRoot /home/httpd/ht ...
- Wamp环境下配置--Apache虚拟主机
1.首先打开apache的配置文件httpd.conf,并去掉#Include conf/extra/httpd-vhosts.conf前面的#,启用虚拟主机功能 # Virtual hosts In ...
- Windows下如何配置apache虚拟主机
其实apache配置虚拟主机说简单也简单,但是就是就有几个坑,要是稍不注意就掉坑里了. --小树前言 坑三连 没遇到这三个坑,就配置得很顺畅了 用自己指定的域名进入不了任何页面. 只能进apache的 ...
- wamp配置apache虚拟主机支持多域名访问localhost
1.背景: 在进行网站开发的时候,通常需要以http://localhost或者127.0.0.1等地址来访问本地环境的网站.不过随着开发项目的增多,需要每次先访问localhost然后再选项目,显得 ...
- windows环境下,apache虚拟主机配置
在windows环境下,apache从配置文件的相关配置: Windows 是市场占有率最高的 PC 操作系统, 也是很多人的开发环境. 其 VirtualHost 配置方法与 Linux 上有些差异 ...
- apache 虚拟主机详细配置:http.conf配置详解
apache 虚拟主机详细配置:http.conf配置详解 Apache的配置文件http.conf参数含义详解 Apache的配置由httpd.conf文件配置,因此下面的配置指令都是在httpd. ...
- Apache虚拟主机配置
在一个Apache服务器上可以配置多个虚拟主机,实现一个服务器提供多站点服务,其实就是访问同一个服务器上的不同目录.Apache虚拟主机配置有3中方法:基于IP配置.基于域名配置和基于端口配置,这里介 ...
随机推荐
- Windows Zip/CentOS/Radhat系统安装Mysql5.7.x方法
CentOS/Redhat 安装: wget http://dev.mysql.com/get/mysql57-community-release-el7-9.noarch.rpm rpm -Uvh ...
- [翻译]SQL Server等待事件—THREADPOOL
前言: 本文是对SQLSkills上一篇关于SQL Server中THREADPOOL等待的博客的翻译,本文也不是完全翻译,有些地方适当加入了自己的一些认知.如有翻译不对或不好的地方,敬请指出,大 ...
- java中 this() 和super()的作用及用法
原文地址:http://www.cnblogs.com/hasse/p/5023392.html 一.This Java关键字this只能用于方法体中.this只能在类中的非静态方法中使用,静态方法和 ...
- Jenkins2.32打包Unity项目的记录
前言 使用jenkins来打包unity3d的工程. jenkins :2.50 /2.32.3(长期支持版 建议使用此版本) 操作系统:windows 7 x64 sp1 (打包安卓和win) ,m ...
- python3使用selenium + Chrome基础操作代码
selenium是Python的第三方库,使用前需要安装.但是如果你使用的是anaconda,就可以省略这个步骤,为啥?自带,任性. 安装命令: pip install selenium (一)使用s ...
- Oracl数据库+PL/SQL安装与配置
资源位置:百度网盘/Oracle+PL/SQL 一.Oracle安装与配置 Oracle 11g 最好安装在Win7上,Win10会有各种不兼容问题. 先安装Oracle数据库,database数据库 ...
- 4.3Python数据处理篇之Matplotlib系列(三)---plt.plot()折线图
目录 前言 (一)plt.plot()函数的本质 ==1.说明== ==2.源代码== ==3.展示效果== (二)plt.plot()函数缺省x时 ==1.说明== ==2.源代码== ==3.展示 ...
- February 17th, 2018 Week 7th Saturday
The happiest part of a man's life is what he passes lying awake in bed in the morning. 人生一大乐事莫过去早上醒来 ...
- React项目中那些奇怪的写法
1.在一个React组件里看到一个奇怪的写法: const {matchs} = this.props.matchs; 原来,是解构赋值,虽然听说过,但是看起来有点奇怪 下面做个实验: <scr ...
- C#反射の反射接口
C#反射の反射详解(点击跳转)C#反射の反射接口(点击跳转)C#反射反射泛型接口(点击跳转)C#反射の一个泛型反射实现的网络请求框架(点击跳转) 上一篇中叙述了反射的情况,下面主要讲一些反射的实际用途 ...