搭建localhost的目錄環境

1、打開系統盤,默認是C:\Windows\System32\drivers\etc,若是系統盤是D盤就打開D:\Windows\System32\drivers\etc:laravel

2、用記事本打開hosts:
3、打開以後默認以下,不太同樣也不要在乎。由於這個有可能不相同的。
4、 127.0.0.1爲本地ip 能夠爲其餘ip設置名稱,本地也能夠添加多個
# 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.com
 
設置以後須要到apache配置文件中配置文件
一、

首先修改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 目錄。

 
 訪問www.fh.com將訪問剛纔設置的自定義文件夾
相關文章
相關標籤/搜索