如何让nginx访问符号路径没有权限问题

如何让nginx访问符号路径没有权限问题

我在 nginx 服务器端创建了一个符号链接路径,它引用我的文档目录

[user1@localhost nginx] pwd 
/user/share/nginx

[user1@localhost nginx] sudo ln -s ~/Documents/nginx-sites/app app
[user1@localhost nginx] ls
lrwxrwxrwx 1 root root   37 Sep 21 14:58 app -> /home/user1/Documents/nginx-sites/app

但是,nginx 用户似乎无法访问该文件(权限被拒绝)

nginx 错误日志在这里-> 2022/09/21 13:35:20 [错误] 20547#20547: *3 open()“/usr/share/nginx/app/public”失败(13:权限被拒绝),客户端:127.0.0.1,服务器:本地主机,请求:“GET /app/public HTTP/1.1”,主机:“本地主机”

所以我尝试表演统计数据通过使用命令http(我的nignx用户)尝试访问该目录,结果如下。

// 1'st tried

[user1@localhost nginx]$ sudo -u http stat app/public
stat: cannot statx 'app/public': Permission denied
// 2nd tried -> cd inside subsequently, and perform stat again

[user1@localhost nginx]$ sudo -u http stat app
 File: app -> /home/user1/Documents/nginx-sites/app
  Size: 37              Blocks: 0          IO Block: 4096   symbolic link
Device: 259,2   Inode: 13375664    Links: 1
...

[user1@localhost nginx]$ cd app
[user1@localhost app]$ sudo -u http stat public
File: public
  Size: 4096            Blocks: 8          IO Block: 4096   directory
Device: 259,2   Inode: 11015535    Links: 2
...

结果,第一次尝试失败,但第二次成功。为什么会出现这种行为?如何制作以下作品?

  1. nginx 用户可以访问并为它们提供服务。
  2. sudo -u http stat app/public 返回成功。
/*For information purpose*/

[user1@localhost ~]$ groups http
user1 http

[user1@localhost ~]$ ls ~/Documents/nginx-sites
drwxr-xr-x 13 user1 user1 4096 Sep 21 14:16 app

[user1@localhost ~]$ ls ~/Documents/nginx-sites/app
drwxr-xr-x  7 user1 user1   4096 Sep 20 21:19 app
-rwxr-xr-x  1 user1 user1   1686 Sep 20 21:19 artisan
drwxr-xr-x  3 user1 user1   4096 Sep 20 21:19 bootstrap
drwxr-xr-x  2 user1 user1   4096 Sep 20 21:19 public

相关内容