搭建localhost的目錄環境


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

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配置文件中配置文件
1、

首先修改C:\Windows\System32\drivers\etc目錄下的 hosts 文件,用記事本打開,加入:

# 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.com

//127.0.0.1 www.a.com127.0.0.1 www.b.com記得去掉前面的

 
2、

打開xampp\apache\conf\httpd.conf文件,搜索 “Include conf/extra/httpd-vhosts.conf”,確保前面沒有 # 注釋符,也就是確保引入了 vhosts 虛擬主機配置文件。效果如下:

# Virtual hosts

Include "conf/extra/httpd-vhosts.conf"

開啟了httpd-vhosts.conf,默認a的httpd.conf默認配置失效(確保 httpd-vhosts.conf 文件里也開啟了虛擬主機配置,見第3條),訪問此IP的域名將全部指向 vhosts.conf 中的第一個虛擬主機。

3、

在虛擬主機設置文件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>

#

# 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將訪問剛才設置的自定義文件夾


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM