美文网首页
mac 安装最新版本nginx教程及403 Forbidden错

mac 安装最新版本nginx教程及403 Forbidden错

作者: leo_xl | 来源:发表于2018-12-02 10:24 被阅读0次

1、更新brew,用来保障安装的nginx是最新版本

brew update

2、安装nginx

brew install nginx

安装的nginx会保存到:/usr/local/Cellar/nginx

nginx配置文件在:/usr/local/etc/nginx/nginx.conf

3、启动nginx

sudo nginx

4、注意事项

nginx配置如下:

location / {
root  /Users/xxxx/Documents/html/;
index  index.html index.htm;
deny all;

修改root地址后,应展示html文件夹下的index.html页面,但是访问却是403 Forbidden报错,这是因为:

根据nginx的 location匹配规则,当一个location 匹配成功以后,会执行该location下指定的root路径。如果该root路径存在并且具有可执行的权限,既可以成功展示对应的index.html(欢迎页),否则跳转默认nginx欢迎页面或者报错404

个例子中root路径是存在的,但是问题就是有没有执行权限。给该root路径的所有文件夹赋予777的权限,问题解决

chmod 777 /Users/xxx/Documents
chmod 777 /Users/xxx/Documents/html

相关文章

网友评论

      本文标题:mac 安装最新版本nginx教程及403 Forbidden错

      本文链接:https://www.haomeiwen.com/subject/shxjcqtx.html