当前位置:网站首页>apache虚拟主机配置的方式有哪些
apache虚拟主机配置的方式有哪些
2022-07-22 05:27:00 【亿速云】
apache虚拟主机配置的方式有哪些
这篇文章主要介绍了apache虚拟主机配置的方式有哪些的相关知识,内容详细易懂,操作简单快捷,具有一定借鉴价值,相信大家阅读完这篇apache虚拟主机配置的方式有哪些文章都会有所收获,下面我们一起来看看吧。
记事本打开httpd.conf文件 ,该文件在apache的目录下,如: D:\AppServ\Apache2.2\conf,修改如下两处:
LoadModule vhost_alias_module modules/mod_vhost_alias.so //去掉前面的#,意思是启用apache的虚拟主机功能,第203行
Include conf/extra/httpd-vhosts.conf //去掉#的意思是从httpd-vhosts.conf这个文件导入虚拟主机配置
配置虚拟主机后 不能用localhost 访问
只需要把httpd.conf文件的ServerName localhost:80 那行注释掉 就可以了
一、基于IP
假设服务器有个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
修改hosts文件,添加三个域名与之一一对应:
192.168.1.11 www.test1.com192.168.1.12 www.test2.com192.168.1.13 www.test3.com
建立虚拟主机存放网页的根目录,如在/www目录下建立test1、test2、test3文件夹,其中分别存放1.html、2.html、3.html
/www/test1/1.html/www/test2/2.html/www/test3/3.html
在httpd.conf中将附加配置文件httpd-vhosts.conf包含进来,接着在httpd-vhosts.conf中写入如下配置:
<VirtualHost 192.168.1.11:80> ServerName www.test1.com DocumentRoot /www/test1/ <Directory "/www/test1"> Options Indexes FollowSymLinks AllowOverride None Order allow,deny Allow From All </Directory></VirtualHost><VirtualHost 192.168.1.12:80> ServerName www.test1.com DocumentRoot /www/test2/ <Directory "/www/test2"> Options Indexes FollowSymLinks AllowOverride None Order allow,deny Allow From All </Directory></VirtualHost><VirtualHost 192.168.1.13:80> ServerName www.test1.com DocumentRoot /www/test3/ <Directory "/www/test3"> Options Indexes FollowSymLinks AllowOverride None Order allow,deny Allow From All </Directory></VirtualHost>
大功告成,测试下每个虚拟主机,分别访问www.test1.com、www.test2.com、www.test3.com
二、基于主机名
设置域名映射同一个IP,修改hosts:
127.0.0.1 gm.998gx.com127.0.0.1 www.998gx.com127.0.0.1 r.998gx.com127.0.0.1 localhost
跟上面一样,建立虚拟主机存放网页的根目录
/www/dxGM/index.php/www/dxskadmin/index.php/www/88qp/index.php
在httpd.conf中将附加配置文件httpd-vhosts.conf包含进来,接着在httpd-vhosts.conf中写入如下配置:
为了使用基于域名的虚拟主机,必须指定服务器IP地址(和可能的端口)来使主机接受请求。可以用NameVirtualHost指令来进行配置。 如果服务器上所有的IP地址都会用到, 你可以用*作为NameVirtualHost的参数。在NameVirtualHost指令中指明IP地址并不会使服务器自动侦听那个IP地址。 这里设定的IP地址必须对应服务器上的一个网络接口。
下一步就是为你建立的每个虚拟主机设定配置块,的参数与NameVirtualHost指令的参数是一样的。每个定义块中,至少都会有一个ServerName指令来指定伺服哪个主机和一个DocumentRoot指令来说明这个主机的内容存在于文件系统的什么地方。
如果在现有的web服务器上增加虚拟主机,必须也为现存的主机建造一个定义块。其中ServerName和DocumentRoot所包含的内容应该与全局的保持一致,且要放在配置文件的最前面,扮演默认主机的角色。
<VirtualHost *:80> DocumentRoot "D:/phpstudy/WWW/dxGM" ServerName gm.998gx.com </VirtualHost><VirtualHost *:80> DocumentRoot "D:/phpstudy/WWW/88qp" ServerName www.998gx.com </VirtualHost><VirtualHost *:80> DocumentRoot "D:/phpstudy/WWW/dxskadmin" ServerName r.998gx.com </VirtualHost><VirtualHost *:80> DocumentRoot "D:/phpstudy/WWW" ServerName localhost </VirtualHost>
4. 大功告成,测试下每个虚拟主机,分别访问gm.998gx.com、www.998gx.com、r.998gx.com
三、基于端口
修改配置文件
将原来的
Listen 80
改为
Listen 80
Listen 8080
更改虚拟主机设置:
<VirtualHost 192.168.1.10:80> DocumentRoot /var/www/test1/ ServerName www.test1.com</VirtualHost><VirtualHost 192.168.1.10:8080> DocumentRoot /var/www/test2 ServerName www.test2.com</VirtualHost>
关于“apache虚拟主机配置的方式有哪些”这篇文章的内容就介绍到这里,感谢各位的阅读!相信大家对“apache虚拟主机配置的方式有哪些”知识都有一定的了解,大家如果还想学习更多知识,欢迎关注亿速云行业资讯频道。
边栏推荐
- 汉得企业级PaaS平台 HZERO 发布 1.5.0.RELEASE 版本
- codeforce D2. RGB Substring (hard version) 滑动窗口
- 跨域问题(CORS)详细说明和解决
- The most detailed conversion of Base64, blob and file
- SAP WPER(POS接口监控器)IDCO过账凭证ALV报表
- 禅道管理员忘记密码找回密码
- [red team] att & CK - browser extension for persistence
- HZERO企业级数字PaaS平台 (二)| 企业级权限体系
- HIAM细粒度统一授权管理助力企业实现系统权限精细化管控
- Visual system design example (Halcon WinForm) -8. matching search
猜你喜欢
[web page performance optimization] - about lazy image loading
MySQL中的日志“binlog”的三种格式这么好玩
Hiam fine-grained unified authorization management helps enterprises achieve refined management and control of system permissions
Under fitting and over fitting (regularization)
Overview of basic principles of network
lvs看这篇就够了
1840. The highest building height is greedy
还在写增删改查代码?直接一键生成
UE4 combines the objects made by the brush into a whole
Enthusiasm and expertise fly together | Microsoft's most valuable expert project, attracting Microsoft technology contributors!
随机推荐
Digital path and practical thinking
tf.get_default_graph
视觉系统设计实例(halcon-winform)-8.匹配查找
tf.random_ normal_ initializer
14_ Response model
ES6 arrow function
汉得企业级数字化PaaS平台 HZERO 1.9.0 版本正式发布!
Ffmpeg-rk3399 ffplay learning analysis
修复版动态视频壁纸微信小程序源码下载,支持多种类型流量主收益
SAP WPER(POS接口监控器)IDCO过账凭证ALV报表
1840. 最高建筑高度 贪心
Can0 transceiver + receive interrupt configuration and baud rate calculation of gd32f470 (detailed)
tf.random_normal_initializer
汉得数字平台体系及试用知多少?
Tensorflow predicts daily sales
Concis组件库 | 暗黑模式设计
Contract awarding and use of NPM private server
【MySQL】sql调优实战教学
FPGA - memory resources of internal structure of 7 Series FPGA -02- FIFO resources
还有人不会这些数据分析小案例吗?一招教你招聘数据可视化~