想在 mac 上配置 nginx 启一个本地服务,访问 localhost ,一直 403 forbidden,心态已崩,求教大神

2019-07-08 16:16:03 +08:00
 maxAir

以下是 nginx.conf 文件配置: user root owner;

user root xl;

user nobody;

worker_processes 1;

#error_log logs/error.log; #error_log logs/error.log notice; #error_log logs/error.log info;

#pid logs/nginx.pid;

events { worker_connections 1024; }

http { include mime.types; default_type application/octet-stream;

#log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
#                  '$status $body_bytes_sent "$http_referer" '
#                  '"$http_user_agent" "$http_x_forwarded_for"';

#access_log  logs/access.log  main;

sendfile        on;
#tcp_nopush     on;

#keepalive_timeout  0;
keepalive_timeout  65;

#gzip  on;

upstream node_server{
  server 127.0.0.1:3000;
  keepalive 2000;
}
server {
    listen       80;
    server_name  localhost;

    location / {
                   root   /Users/xl/Desktop/work/;
                   index  index.html index.htm;
                #    add_header  Access-Control-Allow-Origin *;
                #    add_header  Cache-Control  max-age=3600;
                #    concat on;
                #    concat_max_files 100;
                #    concat_types "application/javascript" "text/css" "text/html";
    }

    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   html;
    }
}



include servers/*;

}

已经检查本地项目目录下所以文件和文件夹都有 rwx 权限; 项目路径在: /Users/xl/Desktop/work;

8305 次点击
所在节点    NGINX
54 条回复
kidlj
2019-07-08 18:45:51 +08:00
应该是访问的目录设置了额外的权限控制(ls 结果有一个 @)。

https://apple.stackexchange.com/questions/42177/what-does-signify-in-unix-file-permissions
maxAir
2019-07-08 22:16:54 +08:00
@kidlj
drwxrwxrwx 5 root admin 160 7 8 21:32 Users
drwxrwxrwx+ 31 xl staff 992 7 8 16:31 xl
去除了 @ 同样报 403 forbidden 呃。。
kidlj
2019-07-08 22:25:05 +08:00
@maxAir 看上边的链接,有 + 号也是设置了额外的权限策略,比如 ACL。

我的 Mac 上也是用 brew 安装和启动的 nginx,配置的目录权限是没有 @ 或者 + 的,访问正常。
maxAir
2019-07-08 22:38:32 +08:00
@kidlj
知道怎么去除这个+ 号吗? , 各种搜没搜到, 只有去除 @ 的, 同样的命令对+ 不管用
kidlj
2019-07-08 22:44:15 +08:00
@maxAir 太晚了,身边也没有电脑。明天我帮你看下。
imdong
2019-07-08 23:03:03 +08:00
localtion 去掉
root index 提取出来放上级
shuangyeying
2019-07-09 06:46:19 +08:00
换个端口试试呗,貌似 macOS 的 80-1024 的端口默认都被占用了。
jorneyr
2019-07-09 07:25:25 +08:00
在根目录下创建一个文件夹 www,给 /www 权限 777,看看能不能跑起来,能跑起来再去研究权限的问题。
leopku
2019-07-09 07:40:18 +08:00
问就换 caddy
michealzh
2019-07-09 09:04:40 +08:00
sudo 启动 nginx
primordial
2019-07-09 09:10:24 +08:00
sudu
primordial
2019-07-09 09:10:42 +08:00
maxAir
2019-07-09 09:23:02 +08:00
@imdong 试过, 和放 location 里面没有区别的
maxAir
2019-07-09 09:24:27 +08:00
@jorneyr 不改访问路径,直接访问 nginx 自己的 index.html 是可以访问的,要指向其它目录就会 403, 应该还是权限问题
zeevin
2019-07-09 09:32:52 +08:00
你要打开 autoindex on; 允许列目录
doublechenpaul
2019-07-09 09:33:23 +08:00
我也是 macos,10.13.2,sudo nginx 没问题
qsbaq
2019-07-09 09:39:04 +08:00
docker +1
jsjscool
2019-07-09 09:40:01 +08:00
文件夹权限原因,root 不要指向 Users 目录。新建一个独立的代码目录,比如 /code/www
kidlj
2019-07-09 09:45:59 +08:00
分别检查一下如下目录的权限:

ls -led /Users/xl/work/
ls -led /Users/xl

然后贴出来。
maxAir
2019-07-09 09:57:52 +08:00
@jsjscool 我在根目录下新建 code 文件夹: 权限:drwxrwxrwx 3 root wheel 96 7 9 09:49 code 一样的效果,code 与 Users 平级的

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/581046

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX