XAMPP on Mac 配置 Virual Host

本文介绍如何在MacOS上通过修改hosts文件及Apache配置文件来设置虚拟主机,包括配置VirtualHost和解决常见403错误的方法。
先在hosts文件里加入virtual host的域名,指向127.0.0.1 我一般使用的命名规则是dev-domainname.com
[python]  view plain copy 在CODE上查看代码片 派生到我的代码片
  1. sudo nano /private/etc/hosts  

[html]  view plain copy 在CODE上查看代码片 派生到我的代码片
  1. # VirtualHosts Mapping  
  2. 127.0.0.1 dev-domainname.com  

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

搜索 “Virtual hosts”
[html]  view plain copy 在CODE上查看代码片 派生到我的代码片
  1. # Virtual hosts  
  2. # Include /Applications/XAMPP/etc/extra/httpd-vhosts.conf  

把第二行注释打开,让Apache去读虚拟主机的配置文件
[html]  view plain copy 在CODE上查看代码片 派生到我的代码片
  1. # Virtual hosts  
  2. Include /Applications/XAMPP/etc/extra/httpd-vhosts.conf  

在以上httpd-vhosts.conf里添加Virtual Host的配置
[html]  view plain copy 在CODE上查看代码片 派生到我的代码片
  1. # localhost  
  2. <VirtualHost *:80>  
  3.     ServerName localhost  
  4.     DocumentRoot "/Applications/XAMPP/xamppfiles/htdocs"  
  5.     <Directory "/Applications/XAMPP/xamppfiles/htdocs">  
  6.         Options Indexes FollowSymLinks Includes execCGI  
  7.         AllowOverride All  
  8.         Require all granted  
  9.     </Directory>  
  10. </VirtualHost>  

[html]  view plain copy 在CODE上查看代码片 派生到我的代码片
  1. # My custom host  
  2. <VirtualHost *:80>  
  3.     ServerName mysite.local  
  4.     DocumentRoot "/Users/yourusername/path/to/your/site"  
  5.     <Directory "/Users/yourusername/path/to/your/site">  
  6.         Options Indexes FollowSymLinks Includes ExecCGI  
  7.         AllowOverride All  
  8.         Require all granted  
  9.     </Directory>  
  10.     ErrorLog "logs/mysite.local-error_log"  
  11. </VirtualHost>  

重启Apache,访问dev-domainname.com出现403错误,在httpd.conf里面搜索User Deamon,把deamon改成OS的用户名,重启Apache,就可以了。


转载:http://blog.youkuaiyun.com/alexjames_83/article/details/40505893
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值