gpt4 book ai didi

php - Nginx 上的 Laravel : accessing to "public/" of the app results in "Permission denied" even though it has the same user as Nginx

转载 作者:行者123 更新时间:2023-12-04 19:30:44 25 4
gpt4 key购买 nike

我一直在尝试使用 CentOS 7 在 Nginx 上部署全新的 Laravel 6 应用程序,但我在错误日志中收到以下错误消息。

*13 stat() "/ROOT_OF_APP/public/" failed (13: Permission denied), 
client: 127.0.0.1, server: HOST_NAME, request: "GET / HTTP/1.1", host: "HOST_NAME"

*13 stat() "/ROOT_OF_APP/public/" failed (13: Permission denied),
client: 127.0.0.1, server: HOST_NAME, request: "GET / HTTP/1.1", host: "HOST_NAME"

*13 FastCGI sent in stderr: "Primary script unknown" while reading response header from upstream,
client: 127.0.0.1, server: HOST_NAME, request: "GET / HTTP/1.1", upstream: "fastcgi://127.0.0.1:9000", host: "HOST_NAME"


第一行是 "/ROOT_OF_APP/public/" failed (13: Permission denied) .

所以,我跑了 sudo chown -R nignx:nginx /ROOT_OF_APP/public/sudo chmod -R 775 /ROOT_OF_APP/ ,并确保 Nginx 和 PHP-FPM 的用户和组都是 nginx (这将在下面解释)。

问题是:
为什么即使所有者/用户是 nginx 也不能访问“公共(public)”?

(第三条消息( Primary script unknown )也困扰着我,但我不知道这是否与权限问题有关)

/etc/php-fpm.d/www.conf ,你会看到这些线。
user = nginx
group = nginx

listen.owner = nginx
listen.group = nginx
listen.mode = 0660

/etc/nginx/nginx.conf ,你看到这条线。
user nginx;

(我想指出操作系统是 CentOS 7 ,所以它没有 www-data 用户/组,不像 Ubuntu 。)

如果我运行 ps aux | grep php-fpm ...
user     24394  0.0  0.0 112708   988 pts/1    S+   14:28   0:00 grep --color=auto php-fpm
root 26979 0.0 0.0 306464 10520 ? Ss 13:57 0:00 php-fpm: master process (/etc/php-fpm.conf)
nginx 26985 0.0 0.0 318712 5804 ? S 13:57 0:00 php-fpm: pool www
nginx 26986 0.0 0.0 318712 5796 ? S 13:57 0:00 php-fpm: pool www
nginx 26987 0.0 0.0 318712 5800 ? S 13:57 0:00 php-fpm: pool www
nginx 26988 0.0 0.0 318712 5800 ? S 13:57 0:00 php-fpm: pool www
nginx 26989 0.0 0.0 318712 5804 ? S 13:57 0:00 php-fpm: pool www

如果我跑了 ps aux | grep nginx ...
root      2990  0.0  0.0 122420  5608 ?        Ss   14:01   0:00 nginx: master process /usr/sbin/nginx
nginx 26985 0.0 0.0 318712 5804 ? S 13:57 0:00 php-fpm: pool www
...
# The 2nd line is repeated several times
...
nginx 31299 0.0 0.0 134672 4212 ? S 14:15 0:00 nginx: worker process
# This "nginx: worker process" is repeated several times too

我完全一无所知...任何建议将不胜感激。

PS

这是配置文件的样子。
server {
listen 80;
listen [::]:80 ipv6only=on;

access_log /var/log/nginx/MY-APP-access.log;
error_log /var/log/nginx/MY-APP-error.log;

root /ROOT_OF_APP/public;
index index.php index.html index.htm;

server_name HOST_NAME;

location / {
try_files $uri $uri/ /index.php?$args;
}

location ~* \.php$ {
include /etc/nginx/fastcgi_params;
fastcgi_pass 127.0.0.1:9000;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_index index.php;
}

location = /favicon.ico { log_not_found off; access_log off; }
location = /robots.txt { log_not_found off; access_log off; }
}
sudo nginx -t表明语法没问题。

此外, "SELinux enforcing" status 已更改为“Permissive”,因此 SELinux 不应该是导致此问题的原因。

最佳答案

当我尝试将我的项目放在/var/www> 之外时,这发生在我身上

我建议把你的项目放在/var/www/project_folder

然后根据需要更改您的 nginx 配置文件。

它会起作用的。

关于php - Nginx 上的 Laravel : accessing to "public/" of the app results in "Permission denied" even though it has the same user as Nginx,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58901117/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com