zoukankan      html  css  js  c++  java
  • apache中vhost的配置

    方法一  Apaceh配置localhost虚拟主机步骤

    1.用记事本打开apache目录下httpd文件(如:C:wampinapacheapache2.2.22conf),找到如下模块

    1. # Virtual hosts
    2. #Include conf/extra/httpd-vhosts.conf

    去掉前面的#,这样就开启了httpd-vhosts虚拟主机文件。这时候重启wamp环境,无法打开localhost,需要在httpd-vhosts.conf配置一下。

    2,用记事本打开httpd-vhosts文件,配置好localhost虚拟主机,参照httpd-vhosts文件中实例,修改成如下:

    1. <VirtualHost *:80>
    2. ServerAdmin webmaster@dummy-host.localhost
    3. DocumentRoot "D:workmgmall_front"
    4. ServerName localhost
    5. ServerAlias localhost
    6. ErrorLog "logs/dummy-host.localhost-error.log"
    7. CustomLog "logs/dummy-host.localhost-access.log" common
    8. </VirtualHost>

    修改配置如下:
    DocumentRoot 修改为本地文件目录(如:D:workmgmall_front)
    ServerName改为localhost

    3,重启Apache,发现localhost可以正常打开,配置localhost比较简单。

    方法二  Apaceh配置testmgmall.com虚拟主机步骤

    1,方法同上,复制配置代码修改如下:

    1. <VirtualHost *:80>
    2. ServerAdmin webmaster@dummy-host.example.com
    3. DocumentRoot "D:workmgmall_front"
    4. ServerName www.testmgmall.com
    5. ServerAlias testmgmall.com
    6. ErrorLog "logs/dummy-host.example.com-error.log"
    7. CustomLog "logs/dummy-host.example.com-access.log" common
    8. </VirtualHost>

    2,打开host文件(C:WindowsSystem32driversetchosts),增加一行代码

    1. 127.0.0.1       testmgmall.com

    3,在浏览器中打开testmgmall.com,发现如下错误

    403 Forbidden错误
    Forbidden
    You don't have permission to access / on this server.

    分析:这主要是目录访问权限没有设置,需要设置对目录的访问权!

    4,打开httpd文件,找到如下语句

    1. <Directory />
    2. Options FollowSymLinks
    3. AllowOverride None
    4. Order deny,allow
    5. Deny from all
    6. </Directory>

    复制以上代码,并进行目录修改,把/替换为D:workmgmall_front,修改VirtualHost 代码如下

    1. <VirtualHost *:80>
    2. ServerAdmin webmaster@dummy-host.example.com
    3. DocumentRoot "D:workmgmall_front"
    4. ServerName www.testmgmall.com
    5. ErrorLog "logs/dummy-host.example.com-error.log"
    6. CustomLog logs/dummy-host.example.com-access.log" common
    7. <Directory D:workmgmall_front>
    8. Options FollowSymLinks
    9. AllowOverride None
    10. Order deny,allow
    11. Deny from all
    12. </Directory>
    13. </VirtualHost>

    在浏览器中测试发现还是打不开,提示如上403 Forbidden错误,修改其中的Deny from all为allow from all

    5,重启Apache,虚拟主机配置成功!

    注意事项
    1,目录路径,如D:workmgmall_front
    2,访问权限,如上Deny from all修改为allow from all
    3,host文件,配置虚拟域名host指向
    4,httpd文件,打开Include conf/extra/httpd-vhosts.conf模块
    5,httpd-vhosts文件,配置虚拟主机

  • 相关阅读:
    (3)合并列值与分拆列值
    (2)SQL语句实现表的横向聚合
    (1)显示每个类别最新更新的数据
    【实践】WCF传输安全2:基于SSL的WCF匿名客户端
    超经典解释什么叫网关
    List集合操作一:遍历与查找
    RGB值及中文名称
    绑定树控件
    treeview的checkbox展开节点
    winform AutoScaleMode属性
  • 原文地址:https://www.cnblogs.com/zhouhaiou/p/4261660.html
Copyright © 2011-2022 走看看