繁体   English   中英

Nginx + php fastcgi无法打开文件,权限被拒绝

[英]Nginx + php fastcgi unable to open file, permission denied

在尝试访问php文件时,我对Nginx和Php fastcgi有一些权限问题。 我在Redhat 7中使用5.5.15和Nginx 1.6.0。

我的php文件现在非常简单。

<?php
echo "\nscript owner : ".get_current_user()."\n";
$myFile = '/usr/share/nginx/html/test.log';
$fh = fopen($myFile, 'a') or die("can''t open file");
?>  

获取当前用户将导致:“myuser”

我得到的错误如下:

2014/08/26 22:47:14 [error] 6424#0: *16 FastCGI sent in stderr: "PHP message: PHP     Warning:  fopen(/usr/share/nginx/html/test.log): failed to open stream: Permission denied     in /usr/share/nginx/html/test.php on line 19" while reading response header from upstream, client: XXXXXX, server: XXXXXXX, request: "GET /test.php HTTP/1.1", upstream: "fastcgi://127.0.0.1:9000", host: "XXXXXXX"

这是目录/ usr / share / nginx的权限(所有父目录都有x权限):

drwxrwsrwx. 4 myuser myuser 4096 Aug 26 22:32 html

运行以下命令:

$ ps aux | grep "nginx: worker process"
myuser  6423  0.0  0.3 111228  3880 ?        S    22:36   0:00 nginx: worker process
myuser  6424  0.0  0.5 111228  5428 ?        S    22:36   0:00 nginx: worker process
myuser  6480  0.0  0.0 112640   980 pts/0    R+   22:41   0:00 grep --color=auto nginx: worker process

$ ps aux | grep "php"
myuser 5930  0.0  0.1 128616  1860 pts/0    T    21:09   0:00 vi /etc/php-fpm.conf
myuser 5931  0.0  0.2 128628  2052 pts/0    T    21:09   0:00 vi /etc/php.ini
myuser  5933  0.0  0.1 128616  1864 pts/0    T    21:13   0:00 vi /etc/php-fpm.conf
myuser  5934  0.0  0.1 128616  1860 pts/0    T    21:14   0:00 vi /etc/php-fpm.d/www.conf
myuser  5935  0.0  0.1 128616  1864 pts/0    T    21:15   0:00 vi /etc/php-fpm.conf
root    6313  0.0  2.4 544732 25208 ?        Ss   22:25   0:00 php-fpm: master process (/etc/php-fpm.conf)
myuser  6314  0.0  0.8 544732  8356 ?        S    22:25   0:00 php-fpm: pool www
myuser  6315  0.0  0.8 544732  8328 ?        S    22:25   0:00 php-fpm: pool www
myuser  6316  0.0  0.9 545076  9892 ?        S    22:25   0:00 php-fpm: pool www
myuser  6317  0.0  0.9 544860  9452 ?        S    22:25   0:00 php-fpm: pool www
myuser  6318  0.0  0.9 544860  9212 ?        S    22:25   0:00 php-fpm: pool www
myuser  6483  0.0  0.0 112640   976 pts/0    R+   22:47   0:00 grep --color=auto php

我的服务器如下所示:

server {
    listen       80;       
    root   /usr/share/nginx/html;


# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
location ~ \.php$ {
    try_files $uri =404;
    fastcgi_split_path_info ^(.+\.php)(/.+)$;
    fastcgi_pass    127.0.0.1:9000;
    fastcgi_index  index.php;
    fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
    include        fastcgi_params;
}

}

在nginx.config中我使用的是同一个用户:“user ec2-user;” 我还将/etc/php-fpm.d/www.conf文件更改为具有相同的用户和组。

user = myuser
group = myuser

因此,Nginx和PHP都在同一个用户“myuser”上运行。 日志文件和php文件所在的所有目录(/ usr / share / nginx / html)都具有x访问权限,并且该用户具有777访问该html目录的权限。

不确定我错过了什么。 我一直在网上搜索2天但没有运气。

我认为权利是正确的,但你在test.php中有3行代码,但由于错误,这不是真的:)检查你运行的文件。

“在第19行的/usr/share/nginx/html/test.php”

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM