# Mac搭建http服务器

Mac系统是自带Apache，所以很方便我们做一些http测试。

```shell
# 启动，重启和停止
sudo apachectl start 
sudo apachectl restart
sudo apachectl stop
# web根目录
/Library/WebServer/Documents
# 这个根目录是可以改的，打开这个配置文件/etc/apache2/httpd.conf，找到DocumentRoot，直接改成想要的目录即可。改完后记得restart服务器。
```

在浏览器打开：[http://localhost](http://localhost/)

将会看到下面信息，说明你们服务器已经启动成功

It works!

然后可以把你的网页丢到`/Library/WebServer/Documents`下面就可以了。

## 如果是通过brew安装的

```
配置文件在：/usr/local/etc/httpd/httpd.conf
配置文件中搜索DocumentRoot可以发现根目录在： /usr/local/var/www

```
