网站运营
位置:首页>> 网站运营>> 详解Mac自带apache配置

详解Mac自带apache配置

作者:0h1in9e  发布时间:2023-09-03 14:48:24 

标签:mac,apache

Mac自身带了apache,可以直接用来搭建本地web容器,配置过程基本同于windows,但有几个点需要注意一下(避免踩坑)

apache


sudo apachectl start[/restart/stop] #开启等

sudo apachectl -v #查看版本

sudo /usr/sbin/httpd -k start #当配置文件出错时,可通过这个方式查看具体出错位置

使用前切记开启一个选项

Mac下apache默认不开启php,需要手动开启


sudo vi /etc/apache2/httpd.conf

LoadModule php5_module libexec/apache2/libphp5.so

Apache修改web目录

默认目录为:


/Library/WebServer/Documents

而往往这个目录用起来是不方便的,一是权限问题,毕竟我们不想每做一次修改,都要带个sudo;二是Finder中打开不方便。所以需要修改web目录。


sudo vi /etc/apache2/httpd.conf

237 DocumentRoot "/Users/username/wwwroot"
238 <Directory "/Users/username/wwwroot">

配置vhost

先开启vhost扩展(去掉注释#即可)


sudo vi /etc/apache2/httpd.conf

Include /private/etc/apache2/extra/httpd-vhosts.conf

编辑vhost文件


sudo vi /etc/apache2/extra/httpd-vhost.conf

<VirtualHost *:80>
 ServerAdmin webmaster@dummy-host.example.com
 DocumentRoot "/Users/username/wwwroot"
 ServerName localhost
 ErrorLog "/private/var/log/apache2/local-error_log"
 CustomLog "/private/var/log/apache2/local-access_log" common
</VirtualHost>

<VirtualHost *:80>
 ServerAdmin webmaster@dummy-host2.example.com
 DocumentRoot "/Volumes/FAT/bugs"
 ServerName wooyun.sb
 ErrorLog "/private/var/log/apache2/wooyun-error_log"
 CustomLog "/private/var/log/apache2/wooyun-access_log" common
 <Directory "/Volumes/FAT/bugs">
       Options Indexes FollowSymLinks MultiViews
       AllowOverride None
       Require all granted
 </Directory>
</VirtualHost>

只允许本机访问

为了安全期间,我打算将apache服务配置成只允许本机访问。网上方法不太适用,经过多次尝试,以下方法可行:


<Directory "/Users/username/sites">
 Options Indexes FollowSymLinks MultiViews
 AllowOverride None
 Require all granted
 # add 访问控制
 Order Deny,Allow  
 Deny from all  #网上很多给出的方法不加这里,只有allow那里,实测并不适用,必须加上这一行~
 Allow from 127.0.0.1  
</Directory>

一些问题处理

1、403 Forbidden

当日志文件log配置出错事,会出现403,处理方法是/var/log/apache2/清空这里边的日志。

也有可能是没有开启PHP扩展。

2、Vhost配置时出现403 Forbidden

注意需要配置文件加入<Directory……部分,如上。

来源:https://www.ohlinge.cn/base/mac_apache.html?utm_source=tuicool&utm_medium=referral

0
投稿

猜你喜欢

手机版 网站运营 asp之家 www.aspxhome.com