Mac OS X 上的Apache配置

Mac系统自带apache服务器

  • 查看apache版本
    sudo apachectl -v
    启动apache
    sudo apachectl start
    重启apache
    sudo apachectl restart
    

      

  • 配置apache
    apache的主配置文件在路径/etc/apache2/下
    • 修改httpd.conf 文件
      • 备份原来的文件
        sudo cp /etc/apache2/httpd.conf /etc/apache2/httpd.conf.backup

      • 修改主配置文件
        $vi /etc/apache2/httpd.conf

      • 主要修改内容

        //181行
        User _www
        Group _www
        //改为(rootname为本机用户名)
        User rootname
        Group wheel
        
        //219行
        <Directory />
          AllowOverride none
          Require all denied
        </Directory>
        //改为(修改apache配置:设置访问代理资源被默认不受限制)
        <Directory />
          Require all granted
          AllowOverride all
        </Directory>
        
        //498行
        # Virtual hosts
        #Include /private/etc/apache2/extra/httpd-vhosts.conf
        //改为(去掉前面的#,这样就开启了httpd-vhosts虚拟主机文件)
        # Virtual hosts 
        Include /private/etc/apache2/extra/httpd-vhosts.conf
        

          

      • 小技巧
        如果你不会使用vi编辑器,没关系

        • 打开Finder
        • 按快键盘 Command + Shift + G调出前往文件夹
        • 输入/etc/apache2即可看到apache配置文件,用自己熟悉编辑器打开httpd.conf就可以求改了,保存的时候需要输入root密码
  • 设置虚拟主机
    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
      • 主要修改内容
        //在文件里加入,前面的例子可以用# 注释掉
        <VirtualHost *:80>
        DocumentRoot "项目文档根目录"
        ServerName 服务器名称
        ErrorLog "/private/var/log/apache2/mysites-error_log"
        CustomLog "/private/var/log/apache2/mysites-access_log" common
        <Directory "项目文档根目录">
        Options FollowSymLinks Multiviews Indexes
        MultiviewsMatch Any
        AllowOverride None
        Require all granted
        </Directory>
        <Proxy *>
        Order deny,allow
        Allow from all
        </Proxy>
        // 配置请求转发服务器 和 环境路径(反向代理)
        ProxyPass /web http://example.com/web
        ProxyPassReverse /web http://example.com/web
        </VirtualHost>
        

          

        设置hosts
  • 打开/etc/hosts文件,加入
    127.0.0.1 你的网站地址
  • 重启Apache服务器
    sudo apachectl restart
  • 打开浏览器输入http://你的网站地址



猜你喜欢

转载自www.cnblogs.com/ryanzheng/p/9939833.html
今日推荐