zoukankan      html  css  js  c++  java
  • Mac OS X上安装配置apache服务器

    说明:Mac在安装完成Mac系统的时候它已经自带了apache服务器,接下来就是配置和将它启动运行了。那么接下来要做的事情就是:

        1.配置apache的配置文件
        2.设置虚拟主机
    

    启动并查看apache

    打开终端输入以下命令:

        $sudo apachectl start
        $sudo apachectl -v
    

    配置apache主配置文件

    apache的主配置文件在路径/etc/apache2/

        先将原来的文件备份
        $sudo cp /etc/apache2/httpd.conf /etc/apache2/httpd.conf.backup
        修改主配置文件
        $vi /etc/apache2/httpd.conf
    

    要修改的地方如下,为了便于参考默认配置,笔者将只是将修改的地方注释掉

        ...
        <Directory />
            #AllowOverride none
            # Require all denied
            Require all granted
            AllowOverride all
        </Directory>
        ... 
    
        # Virtual hosts
        #Include /private/etc/apache2/extra/httpd-vhosts.conf
        Include /private/etc/apache2/extra/httpd-vhosts.conf
        ...
    
    Ps:某些老版本的配置中时allow什么的在网上能找到非常多的教程,在这就不加解释了。
    

    设置虚拟主机

    apache的默认的根目录在/Library/WebServer/下,配置虚拟主机后可以不用理会默认的网站根目录,根据自己的需要在合适的地方建立不同的网站目录。

    修改httpd-vhosts.conf文件,文件位置在/etc/apache2/extra/下.

        备份原有的文件
        $sudo cp /etc/apache2/extra/httpd-vhosts.conf /etc/apache2/extra/httpd-vhosts.conf.backup
    
        $sudo vi /etc/apache2/extra/httpd-vhosts.conf
        设置虚拟主机(此站点本机访问域名是mysite.local,根目录是/var/wwwroot/abc)
        ...
        <VirtualHost *:80>
            ServerAdmin webmaster@mysite.local
            DocumentRoot "/var/wwwroot/abc"
            ServerName mysite.local
            ErrorLog "/private/var/log/apache2/mysite.local-error_log"
            CustomLog "/private/var/log/apache2/mysite.local-access_log" common
        </VirtualHost>
        ...
    

    修改hosts文件,文件位置在/etc/

        $sudo vi /etc/hosts
        将自定义的域名绑定到127.0.0.1
        ...
        127.0.0.1       localhost mysite.local
        ...
    

    重新启动Apache服务器

        sudo apachectl restart
  • 相关阅读:
    SpringMVC传值、转发、重定向例子
    内存、指针操作函数
    文件、磁盘操作函数
    字符串、数组操作函数 Copy Concat Delete Insert High MidStr Pos SetLength StrPCopy TrimLeft
    Delphi代码模拟“显示桌面”的功能
    SQLite 入门教程(四)增删改查,有讲究
    NET Core
    Publisher/Subscriber 订阅-发布模式
    数据分片
    C#调用Java方法
  • 原文地址:https://www.cnblogs.com/zhangwei595806165/p/5599576.html
Copyright © 2011-2022 走看看