您的位置:首页 > 运维架构 > Apache

apache for mac OX S 10.10

2015-07-24 09:52 696 查看
mac下如何针对 apache 设置虚拟目录呢?可能很多人都设置过,但也都不太会,每次都是网上找文章啥的。这里,我自己整理了一点,希望可以帮到大家。

还原 httpd.conf 配置文件

如果,你现在的 /etc/apache2/httpd.conf 文件已经被你改坏了,不用担心,我们还原一些这个文件就好了。具体操作如下:

1、删除当前的 httpd.conf 文件。这个文件一般都会有权限问题,所以需要使用 sudo 去删除,如下:

$ sudo rm /etc/apache2/httpd.conf


  

2、复制一份 /etc/apache2/original/httpd.conf 为 /etc/apache2/httpd.conf 文件。这样我们就有了一份最初默认的 httpd.conf 文件了。

$ cp /etc/apache2/original/httpd.conf /etc/apache2/httpd.conf


  

配置虚拟主机

1、打开 /etc/apache2/httpd.conf 文件,分别找到如下语句去掉前面的 # 。

# 开启虚拟主机别名
LoadModule vhost_alias_module libexec/apache2/mod_vhost_alias.so

# 开启php功能
LoadModule php5_module libexec/apache2/libphp5.so

# 开启虚拟主机配置文件
Include /private/etc/apache2/extra/httpd-vhosts.conf


  

2、打开 /etc/apache2/extra/httpd-vhosts.conf 文件,注释掉默认的虚拟目录配置例子

<VirtualHost *:80>
ServerAdmin webmaster@dummy-host.example.com
DocumentRoot "/usr/docs/dummy-host.example.com"
ServerName dummy-host.example.com
ServerAlias www.dummy-host.example.com
ErrorLog "/private/var/log/apache2/dummy-host.example.com-error_log"
CustomLog "/private/var/log/apache2/dummy-host.example.com-access_log" common
</VirtualHost>

<VirtualHost *:80>
ServerAdmin webmaster@dummy-host2.example.com
DocumentRoot "/usr/docs/dummy-host2.example.com"
ServerName dummy-host2.example.com
ErrorLog "/private/var/log/apache2/dummy-host2.example.com-error_log"
CustomLog "/private/var/log/apache2/dummy-host2.example.com-access_log" common
</VirtualHost>


  以上是apache的例子,先注释掉

3、添加自己的虚拟目录配置

NameVirtualHost *:80

#设置虚拟主机
<VirtualHost *:80>
ServerName prototype.aysee.com
ServerAlias prototype.local.sh.aysee.com
DocumentRoot "/Users/username/Sites/work/_prototype_/"
</VirtualHost>


  然后我们保存文件,重启 Apache

$ sudo apachectl restart


  重启好apache后,打开浏览器输入 127.0.0.1 ,如果可以访问,那么恭喜你,你成功了,如果出现如下提示,那么说明你的配置还是有问题的:

Forbidden

You don't have permission to access / on this server.


  如果出现如上报错,我的解决办法就是,再次打开 httpd-vhosts.conf 文件。在设置虚拟主机那,进行修改,具体修改后代码如下:

# 设置虚拟主机
<VirtualHost *:80>
ServerName prototype.ctrip.com
ServerAlias prototype.local.sh.ctriptravel.com
DocumentRoot "/Users/ctrip_imac/Sites/work/_prototype_/"
<Directory />
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Require all granted
</Directory>
</VirtualHost>


  然后再保存,重启Apache,在浏览器预览 127.0.0.1 ,你会发现成功了。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: