今天在集成环境下配虚拟主机,没想到虚拟主机开启后,localhost竟然无法访问了,解决办法是这样的:

实例一,Apache 配置localhost虚拟主机步骤
1,用记事本打开apache目录下httpd文件(如:D:\wamp\bin\apache\apache2.2.8\conf),找到如下模块
 
    # Virtual hosts
    #Include conf/extra/httpd-vhosts.conf
 
去掉前面的#,这样就开启了httpd-vhosts虚拟主机文件。这时候重启wamp环境,无法打开localhost,需要在httpd- vhosts.conf配置一下。
 
2,用记事本打开httpd-vhosts文件,配置好localhost虚拟主机,参照httpd- vhosts文件中实例,修改成如下:
 
   
    ServerAdmin webmaster@dummy-host.localhost
    DocumentRoot "D:\wamp\www"
    ServerName localhost
    ServerAlias localhost
    ErrorLog "logs/dummy-host.localhost-error.log"
    CustomLog "logs/dummy-host.localhost-access.log" common
   
 
修改配置如下:
DocumentRoot 修改为本地wamp环境下的www目录(如:D:\wamp\www)
ServerName改为localhost
3,重启Apache,发现localhost可以正常打开,配置localhost比较简 单。
 
实例二,Apache配置 test.biuuu.com虚拟主机步骤
 
1,方法同上,复制配置代码修改如下:
 
   
    ServerAdmin test@biuuu.com
    DocumentRoot E:\WebRoot\biuuu
    ServerName test.biuuu.com
    ErrorLog "logs/dummy-host2.localhost-error.log"
    CustomLog "logs/dummy-host2.localhost-access.log" common
   
 
2,打开host文件(C:\WINDOWS\system32\drivers\etc\hosts),增加一行代码
 
    127.0.0.1       test.biuuu.com
 
3,在浏览器中打开test.biuuu.com,发现如下错误403 Forbidden错误
Forbidden
You don't have permission to access / on this server.
 
分析:这主要是目录访问权限没有设置,需要设置对目录的访问权!
 
4,打开httpd文件,找到 如下语句
 
   
    Options FollowSymLinks
    AllowOverride None
    Order deny,allow
    Deny from all
   
 
复制以上代码,并进行目录修改,把/替换为E:\WebRoot\biuuu,修改virtualHost代码如下
 
在浏览器中测试发现还是打不开,提示如上403 Forbidden错误,修改其中的Deny from all为allow from all
 
5,重启Apache,虚拟主机配置成 功!
 
注意事项
1,目录路径,如E:\WebRoot\biuuu
2,访问权限,如上Deny from all修改为allow from all
3,host文件,配置虚拟域名host指向
4,httpd文件,打开Include conf/extra/httpd-vhosts.conf模块
5,httpd-vhosts文件,配置虚拟主机
 
使用 Apache配置httpd-vhosts虚拟主机对于开发人员来说比较简单,但却非常重要,仅供参考!
 
 
 
PS: D:\wamp\alias 也可以这样配置虚拟域名,和例二相同效果
 
 ServerName blog.cc
 ServerAlias blog.cc
 DocumentRoot "D:\wamp\www\blog"
 Options All FollowSymLinks IncludesNOEXEC Indexes
 DirectoryIndex index.html index.htm default.htm index.php default.php index.cgi default.cgi index.shtml index.aspx default.aspx  
 AllowOverride All
 Order Deny,Allow
 Allow from all
 
 
 
 
////////////////////////////////////////////////////////////////////////////////////////////
 
 
 

环境要求

       Apache(HTTPD)我的版本是2.4.3 Win32,你可能需要php引擎模块来测试php网站。
 

配置文件

   假设您已经知道在 httpd.conf 文件中为 main server 配置各种参数包括 DocumentRoot、ServerAdmin、ServerName等。那么配置虚拟主机就很方便了。为了配置文件方便管理,httpd.conf 中有一行指令用来包含外部的配置文件:
Include conf/extra/httpd-vhosts.conf

这行默认是注释掉的,主要是为虚拟主机的配置。所以在该文件(httpd-vhosts.conf)中添加虚拟主机的配置内容:

   如果我在 e:/etc/www/ 下存放了两个网站,一个是 ggicci.cn,一个是 chongwuxingqiu.com。分别存放在 ggicci.cn 目录和 chongwuxingqiu.com 目录下。我现在要为 ggicci.cn 配置成一个虚拟主机,占据端口 81,也就是说我访问该网站需要输入 localhost:81 (本文内容只与本地测试相关,不涉及远程服务器)。chongwuxingqiu.com 同理占据端口 82。我的配置内容如下:
Listen 81  # 监听81端口
<VirtualHost *:81>
ServerAdmin ggicci@163.com
DocumentRoot "e:/etc/www/ggicci.cn" # 网站根目录
DirectoryIndex index.html index.php # 主页索引,因为是php网站,所以添加一个.php的
# ServerName
ErrorLog "logs/ggicci.cn-error.log" # 错误日志
CustomLog "logs/ggicci.cn-access.log" common # 访问日志
</VirtualHost> Listen 82
<VirtualHost *:82>
ServerAdmin ggicci@163.com
DocumentRoot "e:/etc/www/chongwuxingqiu.com"
DirectoryIndex index.html index.jsp # jsp网站,所以添加一个.jsp的
# ServerName
ErrorLog "logs/chongwuxingqiu.com-error.log"
CustomLog "logs/chongwuxingqiu.com-access.log" common JkMount /*.jsp chongwuxingqiu # 这个是 mod_jk 的指令,与 tomcat 相关
</VirtualHost>

测试结果

#e:/etc/www/ggicci.cn/index.php
<?php
echo "ggicci.cn";
?>
 
//e:/etc/www/pet.com/index.jsp
<!DOCTYPE html>
<%@ page contentType="text/html; charset=utf-8"%>
<html>
<head>
<title>宠物星球</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body>
<%
out.println("宠物星球");
%>
</body>
</html>

apache开启虚拟主机localhost无法访问的更多相关文章

  1. Apache配置虚拟主机后,不能访问localhost

    解决方法:将localhost设为虚拟域名 重要的是要注释掉httpd.conf文件的ServerName localhost:80

  2. Linux apache开启虚拟主机伪静态.htaccess

    打开apache配置文件 /etc/httpd/conf/httpd.conf 查找“#LoadModule rewrite_module modules/mod_rewrite.so” 去掉前面的# ...

  3. Apache配置虚拟主机后,不能访问localhost的问题

    今天想试用一下php7,但是发现php7只支持Apache2.4版本,而我电脑上的Apache是2.2版本,为了想尝鲜,就必须去下载新的Apache2.4 php7和apache2.4安装整合以后,l ...

  4. apache开启vhost后localhost和127.0.0.1无法访问

    自己单独搭建了php+mysql+apach+windows环境:后面又开启apache的虚拟主机vhost;然后自己配置虚拟主机站点可以正常访问,但是localhost和127.0.0.1无法访问, ...

  5. 在Apache中开启虚拟主机

    最近在自学LAMP,在Apache中尝试着开启虚拟主机的时候,遇到了挺多麻烦的,这里也顺便总结一下,在Apache中开启虚拟主机的时候,主要有下面几个步骤: 1.新建一个文件夹作为虚拟主机,用来存储网 ...

  6. Apache 创建虚拟主机目录和设置默认访问页面

    虚拟主机 (Virtual Host) 是在同一台机器搭建属于不同域名或者基于不同 IP 的多个网站服务的技术. 可以为运行在同一物理机器上的各个网站指配不同的 IP 和端口, 也可让多个网站拥有不同 ...

  7. Apache配置虚拟主机后让其他电脑访问

    关于Apache配置虚拟主机后在局域网中让其他电脑访问 #test1# NameVirtualHost *:80         ServerName  www.t1.com     Document ...

  8. 【转】Apache 配置虚拟主机三种方式

    Apache 配置虚拟主机三种方式  原文博客http://www.cnblogs.com/hi-bazinga/archive/2012/04/23/2466605.html 一.基于IP 1. 假 ...

  9. win7下配置Apache本地虚拟主机

    我们有时候从网上下载下来的php源码很多都是应用在网站根目录下的,而我们又想在本地先测试一遍确定没有问题了再上传空间,但一换到子目录下的时候因为路径问题,使得许多图片.内容都无法显示. 这个时候我们就 ...

随机推荐

  1. thinkphp笔记

    1.load('@.function')  临时性加载 指的是Common文件下的 function 如 function select(){} , locad中的function实际指的就是 com ...

  2. git alias和gitconfig配置

    [alias] st = status -sb co = checkout br = branch mg = merge ci = commit ds = diff --staged dt = dif ...

  3. Nginx负载均衡配置实例详解(转)

    负载均衡是我们大流量网站要做的一个东西,下面我来给大家介绍在Nginx服务器上进行负载均衡配置方法,希望对有需要的同学有所帮助哦. 负载均衡 先来简单了解一下什么是负载均衡,单从字面上的意思来理解就可 ...

  4. 解决子元素margin让父辈元素位置一起改变的问题

    1.在父元素内添加内容,并且要在子元素块前面添加,后面添加内容无效. 内容可以是文字.图片甚至是空格,源代码里直接按空格无效,可以用占位符  2.让子元素或父元素浮动float:left. 缺点:在元 ...

  5. 详解FindBugs的各项检测器 .

    FindBugs是一个静态分析工具,在程序不需运行的情况下,分析class文件,将字节码与一组缺陷模式进行对比,试图寻找真正的缺陷或者潜在的性能问题.本文档主要详细说明FindBugs 2.0.3版本 ...

  6. tar命令的详细解释

    tar命令的详细解释 标签: linuxfileoutputbashinputshell 2010-05-04 12:11 235881人阅读 评论(12) 收藏 举报  分类: linux/unix ...

  7. centos 安装 mysql5.6

    转载自 http://www.cnblogs.com/littlehb/archive/2013/04/02/2995007.html Mysql 5.5以后使用了CMake进行安装,参考与以前的区别 ...

  8. H5移动端知识点总结

    H5移动端知识点总结 阅读目录 移动开发基本知识点 calc基本用法 box-sizing的理解及使用 理解display:box的布局 理解flex布局 Flex布局兼容知识点总结 回到顶部 移动开 ...

  9. [译]git checkout

    git checkout git checkout提供3种不同的功能: checking out文件, checking out commits, checking out branch. check ...

  10. godaddy空间的sql server数据库没办法insert中文

    原来的代码: use string007 from sysobjects where id = object_id('K_V_TEST') and type = 'U') drop table K_V ...