apache配置本地测试多网站域名与虚拟主机
来源:互联网 发布:十大必看网络小说知乎 编辑:程序博客网 时间:2024/05/21 09:30
1、修改域名访问方式:
运行:C:\WINDOWS\system32\drivers\etc
打开:hosts文件
添加域名指向。
2、修改httpd.conf.
配置生效前提,必须修改跟目录为:
<Directory />
Options FollowSymLinks
AllowOverride None
### Order deny,allow
### Deny from all
Order allow,deny
Allow from all
Satisfy all
</Directory>
否则会出现无权访问问题。
3、虚拟主机的配置
(1)基于IP地址的虚拟主机配置
Listen 80
<VirtualHost 172.20.30.40>
DocumentRoot /www/example1
ServerName www.example1.com
</VirtualHost>
<VirtualHost 172.20.30.50>
DocumentRoot /www/example2
ServerName www.example2.org
</VirtualHost>
(2) 基于IP和多端口的虚拟主机配置
Listen 172.20.30.40:80
Listen 172.20.30.40:8080
Listen 172.20.30.50:80
Listen 172.20.30.50:8080
<VirtualHost 172.20.30.40:80>
DocumentRoot /www/example1-80
ServerName www.example1.com
</VirtualHost>
<VirtualHost 172.20.30.40:8080>
DocumentRoot /www/example1-8080
ServerName www.example1.com
</VirtualHost>
<VirtualHost 172.20.30.50:80>
DocumentRoot /www/example2-80
ServerName www.example1.org
</VirtualHost>
<VirtualHost 172.20.30.50:8080>
DocumentRoot /www/example2-8080
ServerName www.example2.org
</VirtualHost>
(3)单个IP地址的服务器上基于域名的虚拟主机配置:
# Ensure that Apache listens on port 80
Listen 80
# Listen for virtual host requests on all IP addresses
NameVirtualHost *:80
<VirtualHost *:80>
DocumentRoot /www/example1
ServerName www.example1.com
ServerAlias example1.com. *.example1.com
# Other directives here
</VirtualHost>
<VirtualHost *:80>
DocumentRoot /www/example2
ServerName www.example2.org
# Other directives here
</VirtualHost>
(4)在多个IP地址的服务器上配置基于域名的虚拟主机:
Listen 80
# This is the "main" server running on 172.20.30.40
ServerName server.domain.com
DocumentRoot /www/mainserver
# This is the other address
NameVirtualHost 172.20.30.50
<VirtualHost 172.20.30.50>
DocumentRoot /www/example1
ServerName www.example1.com
# Other directives here …
</VirtualHost>
IXDBA.NET社区论坛
<VirtualHost 172.20.30.50>
DocumentRoot /www/example2
ServerName www.example2.org
# Other directives here …
</VirtualHost>
(5)在不同的端口上运行不同的站点(基于多端口的服务器上配置基于域名的虚拟主机):
Listen 80
Listen 8080
NameVirtualHost 172.20.30.40:80
NameVirtualHost 172.20.30.40:8080
<VirtualHost 172.20.30.40:80>
ServerName www.example1.com
DocumentRoot /www/domain-80
</VirtualHost>
<VirtualHost 172.20.30.40:8080>
ServerName www.example1.com
DocumentRoot /www/domain-8080
</VirtualHost>
<VirtualHost 172.20.30.40:80>
ServerName www.example2.org
DocumentRoot /www/otherdomain-80
</VirtualHost>
<VirtualHost 172.20.30.40:8080>
ServerName www.example2.org
DocumentRoot /www/otherdomain-8080
</VirtualHost>
(6)基于域名和基于IP的混合虚拟主机的配置:
Listen 80
NameVirtualHost 172.20.30.40
<VirtualHost 172.20.30.40>
DocumentRoot /www/example1
ServerName www.example1.com
</VirtualHost>
<VirtualHost 172.20.30.40>
DocumentRoot /www/example2
ServerName www.example2.org
</VirtualHost>
<VirtualHost 172.20.30.40>
DocumentRoot /www/example3
ServerName www.example3.net
</VirtualHost>
==========================================================================
简单的说,打开httpd.conf 在最后加入如下内容:
<VirtualHost 127.0.0.2:80>
DocumentRoot d:/AppServ/www2
ServerName 127.0.0.2:80
</VirtualHost>
<Directory "d:/AppServ/www2">
Options Indexes FollowSymLinks Multiviews
AllowOverride All
Order Allow,Deny
Allow from all
</Directory>
"d:/AppServ/www2" 为你的站点存放目录:重启apache2以后,你的虚拟主机就配置好了,以后就可以通过127.0.0.2,和127.0.0.3进入不同的站点了。
下面为详细说明分析:
在我们安装APACHE的时候一般默认的apache的配置是只有一个网站,这样切换起来很不方便。其实这个问题很好解决,就是把本机的 apache配置成为虚拟服务器。但是,网上大多数教程的是教用 apache如何配置基于域名的虚拟主机的,而在本机调试网站的时候,一般都是用本地ip(127.0.0.1 或 localhost)直接访问,没有用到域名。所以得把apache配置成为基于ip地址的虚拟主机。
首先,我们都知道,所有以127打头的ip地址都应该指向本机,并不只有127.0.0.1,这点大家可以试试。
这样一来,也就是说本机有足够多的ip地址供你来开设虚拟主机了。
废话少说,进入正式的配置工作,下面是apache的httpd.conf里相关配置部分( httpd.conf 位于 Apache2.2\conf ):
1、Listen部分,必须直接指定端口,不指定ip地址,配置应写为:
Listen 80
2、不用像基于域名的虚拟主机那样写“NameVirtualHost”。
3、虚拟主机配置段:在httpd.conf 最后加上
<VirtualHost 127.0.0.2:80>
DocumentRoot d:/AppServ/www2
ServerName 127.0.0.2:80
</VirtualHost>
<VirtualHost 127.0.0.3:80>
DocumentRoot d:/AppServ/www3
ServerName 127.0.0.3:80
</VirtualHost>...
4、然后相应的配置好各个目录属性,下面是一个目录属性的典型配置:
<Directory "d:/AppServ/www2">
Options Indexes FollowSymLinks Multiviews
AllowOverride All
Order Allow,Deny
Allow from all
</Directory>
<Directory "d:/AppServ/www3">
Options Indexes FollowSymLinks Multiviews
AllowOverride All
Order Allow,Deny
Allow from all
</Directory>
重启apache2以后,你的虚拟主机就配置好了,以后就可以通过127.0.0.1和127.0.0.2,127.0.0.3进入不同的站点了。
- apache配置本地测试多网站域名与虚拟主机
- Apache配置本地测试多网站域名与虚拟主机
- Apache配置本地测试多网站域名与虚拟主机
- apache配置本地测试多网站域名与虚拟主机
- Apache配置本地测试多网站域名与虚拟主机
- apache本地虚拟主机配置(多域名,单IP)【转】
- apache 本地配置虚拟主机,单ip多域名
- Apache配置虚拟主机&设置本地域名
- Apache虚拟主机的配置多地址,多网站,域名访问
- Apache配置虚拟主机域名
- apache配置虚拟主机域名
- apache添加虚拟主机配置+本地hosts绑定域名
- PHP本地实现虚拟域名访问:Apache虚拟主机配置
- apache+tomcat多个域名,虚拟主机配置
- apache平台下配置多域名虚拟主机
- apache本地配置多域名(wampserver本地配置多域名)
- apache本地配置多域名(wampserver本地配置多域名)
- apache本地配置多域名(wampserver本地配置多域名)
- 联网状态下,ARCGIS 10无法启动的问题
- 克强经济学 程序员你看吗?
- erro: "Instantiation of '***' failed. The design unit was not found"
- c# WinForm实现窗体上控件的自由拖动
- 做管件网络销售之前,必须要做的三件事
- apache配置本地测试多网站域名与虚拟主机
- OSTimeTick()函数解析
- HDOJ1527 [威佐夫博弈]【典型】
- IOS静态库相关-封装lib
- hdu1240
- 如何解决office2007无法重装的问题
- 每日一题(31) - 二叉树的镜像
- AutoCompleteTextView与MultiAutoCompleteTextView
- Eclipse自动补全功能轻松设置