zoukankan      html  css  js  c++  java
  • apache for mac OX S 10.10

    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 ,你会发现成功了。

  • 相关阅读:
    3.4.4 反射和泛型
    4.4.2 空合并操作符让比较不再痛苦
    NPOI导出EXCEL 打印设置分页及打印标题
    20、异常和状态管理
    14 字符字符串和文本处理
    15、枚举类型和标志位
    Oracle 数据库连接的一些坑
    17、委托
    《山鬼·九歌》——屈原
    每周一卦测感情,还是这么凶
  • 原文地址:https://www.cnblogs.com/ayseeing/p/4672525.html
Copyright © 2011-2022 走看看