PHP群:95885625 Hbuilder+MUI群:81989597 站长QQ:634381967
    您现在的位置: 首页 > 服务器 > Web服务器 > 正文

    apache怎么配置虚​拟​主​机?

    作者:w634381967来源:网络浏览:时间:2020-09-30 00:07:50我要评论
    导读:h​t​t​p​d​​v​h​o​s​t​s​文件在apache中配置是非常重要的一个环节了,我们可以把所有目录都配置到h​t​t​p​d​​v​h​o​s...
    h​t​t​p​d​​v​h​o​s​t​s​文件在apache中配置是非常重要的一个环节了,我们可以把所有目录都配置到h​t​t​p​d​​v​h​o​s​t​s​中,下面整理了一些例子,我们一起来看看。
    实例一,Apache 配置localhost虚拟主机步骤
    1,用记事本打开apache目录下httpd文件(如:D:wampbinapacheapache2.2.8conf),找到如下模块
    # Virtual hosts
    #Include conf/extra/httpd-vhosts.conf
    去掉前面的#,这样就开启了httpd-vhosts虚拟主机文件。这时候重启wamp环境,无法打开localhost,需要在httpd- vhosts.conf配置一下。
    2,用记事本打开httpd-vhosts文件,配置好localhost虚拟主机,参照httpd- vhosts文件中实例,修改成如下:
    <VirtualHost *:80>
    ServerAdmin webmaster@dummy-host.localhost
    DocumentRoot “D:wampwww”
    ServerName localhost
    ServerAlias localhost
    ErrorLog “logs/dummy-host.localhost-error.log”
    CustomLog “logs/dummy-host.localhost-access.log” common
    </VirtualHost>
    修改配置如下:
    DocumentRoot 修改为本地wamp环境下的www目录(如:D:wampwww)
    ServerName改为localhost
    3,重启Apache,发现localhost可以正常打开,配置localhost比较简 单。
    实例二,Apache配置 www.bcty365.com虚拟主机步骤
    1,方法同上,复制配置代码修改如下:
    <VirtualHost *:80>
    ServerAdmin test@biuuu.com
    DocumentRoot E:WebRootbiuuu
    ServerName www.111cn.net
    ErrorLog “logs/dummy-host2.localhost-error.log”
    CustomLog “logs/dummy-host2.localhost-access.log” common
    </VirtualHost>
    2,打开host文件(C:WINDOWSsystem32driversetchosts),增加一行代码
    127.0.0.1       www.111cn.net
    3,在浏览器中打开www.111cn.net,发现如下错误403 Forbidden错误
    Forbidden
    You don’t have permission to access / on this server.
    分析:这主要是目录访问权限没有设置,需要设置对目录的访问权!
    4,打开httpd文件,找到 如下语句
    <Directory />
    Options FollowSymLinks
    AllowOverride None
    Order deny,allow
    Deny from all
    </Directory>
    复制以上代码,并进行目录修改,把/替换为E:WebRootbiuuu,修改virtualHost代码如下
    <VirtualHost *:80>
    ServerAdmin test@biuuu.com
    DocumentRoot E:WebRootbiuuu
    ServerName www.111cn.net
    ErrorLog “logs/dummy-host2.localhost-error.log”
    CustomLog “logs/dummy-host2.localhost-access.log” common
    <Directory E:WebRootbiuuu>
    Options FollowSymLinks
    AllowOverride None
    Order deny,allow
    Deny from all
    </Directory>
    </VirtualHost>
    在浏览器中测试发现还是打不开,提示如上403 Forbidden错误,修改其中的Deny from all为allow from all
    5,重启Apache,虚拟主机配置成 功!
    注意事项
    1,目录路径,如E:WebRootbiuuu
    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:wampalias 也可以这样配置虚拟域名,和例二相同效果
    <VirtualHost *:80>
    ServerName blog.cc
    ServerAlias blog.cc
    DocumentRoot “D:wampwwwblog”
    <Directory “D:wampwwwblog”>
    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
    </Directory>
    </VirtualHost>
    最后我们对php.ini做一下安全配置吧
    disable_functions = 在这里可以限制php函数
    转载请注明(B5教程网)原文链接:https://b5.mxunkeji.com/content-122-1261-1.html
    相关热词搜索: