配置apache虚拟主机具体步骤详解(配置虚拟域名指向本地主机)

配置apache虚拟主机具体步骤详解(配置虚拟域名指向本地主机)

ps:本人亲测,阿里云2核4G5M的服务器性价比很高,新用户一块多一天,老用户三块多一天,最高可以买三年,感兴趣的可以戳一下:阿里云折扣服务器

配置虚拟域名:

1、开启apache的mod_rewrite功能模块

2、引入http-vhosts.conf文件

3、添加VirtualHost配置

具体步骤:

1、打开XAMPP->Apache->conf->httpd.conf(也可以直接从XAMPP中直接打开配置文件)

2、搜索rewrite,取消掉LoadModule rewrite_module modules/mod_rewrite.so这一行的注释。然后找到vhosts.conf,找到# Virtual hosts
#Include conf/extra/httpd-vhosts.conf
这一段把Include conf/extra/httpd-vhosts.conf前面的"#"去掉。

3、在httpd.conf里的DocumentRoot "C:/xampp/htdocs"前面加上#

4、在DocumentRoot下面的Directory前面加上#,如下图:

#<Directory "C:/xampp/htdocs">
    #
    # Possible values for the Options directive are "None", "All",
    # or any combination of:
    #   Indexes Includes FollowSymLinks SymLinksifOwnerMatch #ExecCGI MultiViews
    #
    # Note that "MultiViews" must be named *explicitly* --- #"Options All"
    # doesn't give it to you.
    #
    # The Options directive is both complicated and important.  #Please see
    # http://httpd.apache.org/docs/2.4/mod/core.html#options
    # for more information.
    #
#    Options Indexes FollowSymLinks Includes ExecCGI

    #
    # AllowOverride controls what directives may be placed in #.htaccess files.
    # It can be "All", "None", or any combination of the keywords:
    #   AllowOverride FileInfo AuthConfig Limit
    #
#    AllowOverride All

    #
    # Controls who can get stuff from this server.
    #
#    Require all granted
#</Directory>

5、在conf/extra/httpd-vhosts.conf文件下面添加htdocs(根目录),因为上面的3、4步已经去掉了根目录配置,如下图:

<VirtualHost *:80>
    DocumentRoot "C:/xampp/htdocs"
    ServerName 127.0.0.1:80
    ServerAlias localhost
    ServerAdmin webmaster@localhost
    DirectoryIndex index.html index.htm index.php default.php app.php u.php
    ErrorLog logs/localhost_error.log
    CustomLog logs/localhost_access_%Y%m%d.log comonvhost
<Directory "C:/xampp/htdocs">
    Options FollowSymLinks
    AllowOverride All
    Require all granted
</Directory>
</VirtualHost>



**(一般直接进行下面两步就可以了)**

6、打开conf/extra/httpd-vhosts.conf文件,在最下方添加(为apache添加虚拟主机),如下图:

<VirtualHost *:80>
    DocumentRoot "F:/youzhiwang"
    ServerName youzhiwang.com:80
    ServerAlias 
    ServerAdmin webmaster@test123.com
    DirectoryIndex index.html index.htm index.php default.php app.php u.php
    ErrorLog logs/test123.com-error.log
    CustomLog logs/test123.com-access_%Y%m%d.log comonvhost
<Directory "F:/youzhiwang">
    Options FollowSymLinks
    AllowOverride All
    Require all granted
</Directory>
</VirtualHost>


7、修改修改位于(win7)c:/windows/system32/drivers/etc/目录下的hosts文件(添加本地主机域名解析)

增加一段:127.0.0.1    x.acme.com(你自己指定用来访问的域名)

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值