您的位置:首页 > 运维架构 > Apache

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

2016-03-29 14:09 886 查看

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

配置虚拟域名:

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(你自己指定用来访问的域名)
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息