XAMPP on Mac 组态 Virual Host

时间:2022-02-17 04:04:54
首先,在hosts文件中添加virtual host域名。方向127.0.0.1 我一般使用的命名约定dev-domainname.com
sudo nano /private/etc/hosts

# VirtualHosts Mapping
127.0.0.1 dev-domainname.com

接下来配置Apache。打开Apache的配置文件 /Applications/XAMPP/etc/httpd.conf


搜索 “Virtual hosts”
# Virtual hosts
# Include /Applications/XAMPP/etc/extra/httpd-vhosts.conf

把第二行凝视打开,让Apache去读虚拟主机的配置文件

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

在以上httpd-vhosts.conf里加入Virtual Host的配置

# localhost
<VirtualHost *:80>
ServerName localhost
DocumentRoot "/Applications/XAMPP/xamppfiles/htdocs"
<Directory "/Applications/XAMPP/xamppfiles/htdocs">
Options Indexes FollowSymLinks Includes execCGI
AllowOverride All
Require all granted
</Directory>
</VirtualHost>
# My custom host
<VirtualHost *:80>
ServerName mysite.local
DocumentRoot "/Users/yourusername/path/to/your/site"
<Directory "/Users/yourusername/path/to/your/site">
Options Indexes FollowSymLinks Includes ExecCGI
AllowOverride All
Require all granted
</Directory>
ErrorLog "logs/mysite.local-error_log"
</VirtualHost>

重新启动Apache,訪问dev-domainname.com出现403错误,在httpd.conf里面搜索User Deamon,该deamon变OS的username。重新开始Apache。在上面。

版权声明:本文博客原创文章,博客,未经同意,不得转载。