`
magicmind
  • 浏览: 74545 次
  • 性别: Icon_minigender_1
  • 来自: 郑州
社区版块
存档分类
最新评论

Apache配置虚拟主机和虚拟目录

    博客分类:
  • web
阅读更多

 

今天需要给apache配置虚拟主机,把从网上搜到的内容总结一下:

Apache 配置虚拟主机

1.       方式一:使用不同的服务端口,启动多个apache服务实例,使用各自的配置文件

1)  创建配置文件:复制httpd.conf 另存为mysite.conf(名字自定)

2)  修改新配置文件里的监听端口:找到“Listen:80” 改为“Listen:8080”80以外的端口)

3)  设置站点目录:指定 DocumentRoot "×××××" <Directory "××××">的目录名 

4)  新建一个服务:httpd -k install -n "服务名" -f "配置文件路径"

2.       方式二:同一个端口,配置多个虚拟主机

1)  修改配置httpd.conf

a.       注释掉DocumentRoot

b.       找到Include conf/extra/httpd-vhosts.conf,如果有注释则打开

2)  修改配置文件/conf/extra/httpd-vhosts.conf

a.       去掉NameVirtualHost的注释,NameVirtualHost  ip:80 (本机ip*:80 表示所有ip

b.       增加虚拟主机的配置。Httpd-vhosts.conf里有例子

             <VirtualHost *:80>

     ServerName "localhost"

                   DocumentRoot "/www/root"

             </VirtualHost>

             <VirtualHost *:80>

      ServerName "localhost2"

                    DocumentRoot "/www/root2"

             </VirtualHost>

    * 访问虚拟主机如果出现

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

    这是因为新建的虚拟主机的目录没有读权限。做如下操作:

      1. 把相应目录的权限改为可读。

      2. 在虚拟主机配置后面添加如下代码

<Directory "D:/Web">
    Options FollowSymLinks
    AllowOverride None
    Order deny,allow
    Allow from all
</Directory>

 

Apache 配置虚拟目录

  编辑httpd.conf文件,增加

     Alias /xx  “实际目录路径

 和上面虚拟主机的配置一样,下面也需要加目录权限配置<Directory>,否则也不能访问。

 

 

 

 

 

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics