Mac OS X (El Capitan) Virtual Hosts 设置

  • 发表于
  • macOS

Mac OS X (El Capitan) Virtual Hosts(虚拟主机) 设置

所需用到文件:

  1. /Applications/XAMPP/xamppfiles/etc/httpd.conf
  2. /Applications/XAMPP/xamppfiles/etc/extra/httpd-vhosts.conf
  3. /etc/hosts

httpd.conf

找到

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

改为:

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

httpd-vhosts.conf

创建新的虚拟主机配置:

# My WebService host
<VirtualHost *:80>
ServerName webservice.local
DocumentRoot "/Applications/XAMPP/xamppfiles/htdocs/api/public"
<Directory "/Applications/XAMPP/xamppfiles/htdocs/api/public ">
Options Indexes FollowSymLinks Includes ExecCGI
AllowOverride All
Require all granted
</Directory>
ErrorLog "logs/webservice.local-error_log"
</VirtualHost>

其中webservice.local为你的解析域名

hosts file

命令:sudo nano /etc/hosts

# XAMPP VirtualHost mappings
127.0.0.1 webservice.local

 

结束;但有部分朋友会出现

403 Error

打开/Applications/XAMPP/xamppfiles/etc/httpd.conf

# User/Group: The name (or #number) of the user/group to run httpd as.
# It is usually good practice to create a dedicated user and group for
# running httpd, as with most system services.
#
User daemon
Group daemon

把User daemon 中的 daemon改为你的MAC的用户名即可!

参考:

http://mrgott.com/misc/20-setting-up-virtual-hosts-for-xampp-on-mac-os-x-el-capitan