文件目錄 xampp => apach e=>httpd.conf
1.在文件內搜索 關鍵字“httpd-vhosts.conf”,找到如下字段
# Virtual hosts
Include conf/extra/httpd-vhosts.conf//確保此段開頭沒有#
2.在文件內搜索關鍵字“AllowOverride All”,找到如下字段
<Directory "D:/xampp/cgi-bin">
AllowOverride All
Options None
Require all granted
</Directory>
//修改爲
<Directory "D:/xampp/cgi-bin">
Options Indexes FollowSymLinks Includes ExecCGI
AllowOverride All
Order allow,deny
Allow from all
</Directory>
3.搜索字段“DocumentRoot”,如下
DocumentRoot "D:/xampp/htdocs"//確保此處路徑是你要訪問的項目的根路徑
<Directory "D:/XAMPP/htdocs">//確保此處路徑是你要訪問的項目的根路徑
4.如果想自定義配置端口,搜索字段“Listen 80”,找到如下
Listen 80
//在此添加你想監聽的端口,如
Listen 80
Listen 8080
Listen 8099
....
文件目錄 xampp => apache =>conf => extra => httpd-vhosts.conf
文件最後面可看到如下
##<VirtualHost *:80>
##ServerAdmin [email protected]
##DocumentRoot "D:/xampp/htdocs/dummy-host2.example.com"
##ServerName dummy-host2.example.com
##ErrorLog "logs/dummy-host2.example.com-error.log"
##CustomLog "logs/dummy-host2.example.com-access.log"
##</VirtualHost>
<VirtualHost *:80>
DocumentRoot "D:/XAMPP/htdocs"
ServerName www.myWeb.com//除了localhost外還可以訪問的域名
</VirtualHost>
1.用ip訪問
<VirtualHost 127.0.0.1:80>//設置訪問的ip
##ServerAdmin [email protected]
DocumentRoot "D:/xampp/htdocs/project"//你的項目文件目錄
ServerName www.myWeb.com//此項目的名稱
##ErrorLog "logs/dummy-host2.example.com-error.log"
##CustomLog "logs/dummy-host2.example.com-access.log"
</VirtualHost>
2.用ServerName訪問
<VirtualHost *:80>
##ServerAdmin [email protected]
DocumentRoot "D:/xampp/htdocs/project"//你的項目文件目錄
ServerName www.myWeb.com//此項目的名稱,通過此名稱來訪問項目,還需配置hosts文件
##ErrorLog "logs/dummy-host2.example.com-error.log"
##CustomLog "logs/dummy-host2.example.com-access.log"
</VirtualHost>
3.配置hosts文件
文件目錄 C:\Windows\System32\drivers\etc\hosts
在文件中加入
127.0.0.1 www.myWeb.com
*域名不要帶下劃線等特殊符號