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

在尝试访问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访问权限,并且该用户可以访问该html目录。

不知道我缺less什么。 我一直在网上search了2天,但没有运气。

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

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