MAC自带apache开启目录访问及基本配置

admin 2020-4-21 235

切到root帐号

sudo su

查看当前版本

 httpd -v

配置文件与网站根目录默认所在位置

/etc/apache2/httpd.conf //配置文件/Library/WebServer/Documents //网站根目录

服务基本操作

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

开启目录浏览


修改/etc/apache2/httpd.conf,把Options  FollowSymLinks Multiviews改成Options Indexes FollowSymLinks Multiviews

<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>

其它操作:去除配置文件的空行与以#开头的行

cp /etc/apache2/httpd.conf /etc/apache2/httpd.conf.back //备份grep -Ev "^$|[#;]" /etc/apache2/httpd.conf > /etc/apache2/httpd.conf  /去除空行与#号行

总结:
apache出现403 Forbidden主要有两个原因:
1是DocumentRoot目录或以下的文件没有权限,如:把文档目录设成/root/abcd,因为root目前默认没有X权限导致403,又或者具体文件没有644 权限

#查看目录权限
ll /root
drwxrwx---.  11 root root 4096 Feb 24 02:18 root
#通过以下命令修改
chmod 641 /root 
#查看文件权限
-rw-r-----  1 root root  52532 Feb 24 02:37 index.html
#通过以下命令修改
chmod 644 index.html
-rw-r--r--  1 root root  52532 Feb 24 02:37 index.html

目录权限修改说明: R=4 ,W=2 ,X=1 (R表示读,W表示写,X表示执行)
rwx 相加就是 7
2是apache配置文件问题,需要修改http.conf文件。



作者:wsf535
链接:https://www.jianshu.com/p/a617691a7f4f
来源:简书
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。


最新回复 (0)
返回