Mac自带apache服务器配置

322 阅读1分钟

这段时间在看iOS网络相关知识点,想动手练习下,发现没有现成服务器,什么都做不了。发现可以使用mac自带apache服务器,只需要两分钟就可以搭建开启自己的apache服务器,进行文件上传、下载等操作,感兴趣可以动手试下。

搭建步骤

1、打开配置文件:

/etc/apache2/httpd.conf

2、配置文件

<Directory />
     AllowOverride none
     Require all granted
     Allow from all
</Directory>
DocumentRoot "/Library/WebServer/Documents"
<Directory "/Library/WebServer/Documents">
    Options Indexes FollowSymLinks Multiviews
    MultiviewsMatch Any
    AllowOverride All
    Require all granted
</Directory>

要配置DocumentRoot和Directory后面的文件路径,表示apache根目录。“Options FollowSymLinks Multiviews”改成“Options Indexes FollowSymLinks Multiviews”

3、服务器基本操作

sudo apachectl start // 开启Apache
sudo apachectl stop // 关闭Apache
sudo apachectl restart // 重启Apache

错误类型

1、无权限获取资源 image.png 这种case要把文件夹路径上所有的文件的权限设置成读和写,注意ask-everyone权限也一定要设置成读和写

image.png 2、未打开apache服务 image.png 终端输入命令:sudo apachectl stop