1.进入config文件

打开Apache安装目录下的配置文件conf/extra/httpd-vhosts.conf

<VirtualHost *:80>
    ServerAdmin webmaster@dummy-host.example.com
    DocumentRoot "/Applications/XAMPP/xamppfiles/docs/dummy-host.example.com"
    ServerName dummy-host.example.com
    ServerAlias www.dummy-host.example.com
    ErrorLog "logs/dummy-host.example.com-error_log"
    CustomLog "logs/dummy-host.example.com-access_log" common
</VirtualHost>

ServerAdmin      网站的管理员的邮箱
DocumentRoot     虚拟主机的主目录
ServerName       主机名
ServerAlias      主机的别名
ErrorLog         错误的日志
CustomLog        虚拟主机访问的日志

2.进入hosts文件中加入域名到本地IP地址的映射

win:

hosts文件位置:C:\Windows\System32\drivers\etc

注意:这里有两个hosts文件,hosts.ics 文件是临时的,所以我们修改HOSTS文件。

// 添加下面的代码
127.0.0.1       jtw.com

mac:

进入本地配置文件:

sudo vi /etc/hosts    输入密码,修改文件

3.重启 xampp 的 Apache

进入设置网址,例如:http://blog.com:8080/

查看是否进入指定项目地址,如果没有进入,可能没有开启虚拟web服务文件

解决办法:

进入/……/XAMPP/xamppfiles/etc/httpd.conf,注销httpd-vhosts.conf引入代码,如:

# Virtual hosts
Include etc/extra/httpd-vhosts.conf

重启

4.再次输入地址,验证是否成功

Logo

华为开发者空间,是为全球开发者打造的专属开发空间,汇聚了华为优质开发资源及工具,致力于让每一位开发者拥有一台云主机,基于华为根生态开发、创新。

更多推荐