1、打開系統盤,默認是C:\Windows\System32\drivers\etc,若是系統盤是D盤就打開D:\Windows\System32\drivers\etc:laravel
首先修改C:\Windows\System32\drivers\etc目錄下的 hosts 文件,用記事本打開,加入:apache
# Copyright (c) 1993-2009 Microsoft Corp.
# This is a sample HOSTS file used by Microsoft TCP/IP for Windows.
#
# This file contains the mappings of IP addresses to host names. Each
# entry should be kept on an individual line. The IP address should
# be placed in the first column followed by the corresponding host name.
# The IP address and the host name should be separated by at least one
# space.
#
# Additionally, comments (such as these) may be inserted on individual
# lines or following the machine name denoted by a '#' symbol.
#
# For example:
#
# 102.54.94.97 rhino.acme.com # source server
# 38.25.63.10 x.acme.com # x client host
# localhost name resolution is handled within DNS itself.
127.0.0.1 localhost
127.0.0.1 www.test.com
127.0.0.1 www.fh.com
127.0.0.1 www.test_my.comapp
//127.0.0.1 www.a.com127.0.0.1 www.b.com記得去掉前面的post
打開xampp\apache\conf\httpd.conf文件,搜索 「Include conf/extra/httpd-vhosts.conf」,確保前面沒有 # 註釋符,也就是確保引入了 vhosts 虛擬主機配置文件。效果以下:spa
# Virtual hostsserver
Include "conf/extra/httpd-vhosts.conf"ip
開啓了httpd-vhosts.conf,默認a的httpd.conf默認配置失效(確保 httpd-vhosts.conf 文件裏也開啓了虛擬主機配置,見第3條),訪問此IP的域名將所有指向 vhosts.conf 中的第一個虛擬主機。requests
在虛擬主機設置文件xampp\apache\conf\extra \httpd-vhosts.conf裏設置:取消 NameVirtualHost *:80 前面的 ##,這樣就啓用了 vhosts.conf ,默認的httpd.conf默認配置失效。虛擬主機配置將只設置在httpd-vhosts.conf裏。localhost 的目錄默認配置記得也按此設置。域名
<VirtualHost *:80>
ServerAdmin fh@fh.com
DocumentRoot "D:/feihu/xampp/htdocs/mylaravel/public"
ServerName www.fh.com
ErrorLog "logs/fh.com-error.log"
CustomLog "logs/fh.com-access.log" common
</VirtualHost>it
#
# Use name-based virtual hosting.
#
NameVirtualHost *:80
#
# VirtualHost example:
# Almost any Apache directive may go into a VirtualHost container.
# The first VirtualHost section is used for all requests that do not
# match a ServerName or ServerAlias in any block.
#
ServerAdmin postmaster@dummy-host.localhost
DocumentRoot "I:/xampp/htdocs/"
ServerName localhost
ServerAlias localhost
ErrorLog "logs/dummy-host.localhost-error.log"
CustomLog "logs/dummy-host.localhost-access.log" combined
ServerAdmin postmaster@dummy-host1.localhost
DocumentRoot "I:/xampp/htdocs/a"
ServerName www.a.com
ServerAlias www.a.com
ErrorLog "logs/dummy-host1.localhost-error.log"
CustomLog "logs/dummy-host1.localhost-access.log" combined
ServerAdmin postmaster@dummy-host2.localhost
DocumentRoot "I:/xampp/htdocs/b/"
ServerName www.b.com
ServerAlias www.b.com
ErrorLog "logs/dummy-host2.localhost-error.log"
CustomLog "logs/dummy-host2.localhost-access.log" combined
//至此,XAMPP 的虛擬主機設置完畢,如今 訪問 localhost 仍是原來的 XAMPP 的幫助指南,訪問 www.a.com 將指向到綁定的 a 目錄,訪問 www.b.com 將指向到綁定的 b 目錄。