我读了几篇关于为什么PHP-FPM可能会拒绝我的权限的问题,但是我无法解决这个问题。
错误日志如下所示:
2013/04/20 23:33:28 [crit] 15479#0: *6 open() "/var/lib/nginx/tmp/fastcgi /2/00/0000000002" failed (13: Permission denied) while reading upstream, client: 99.999.999.999, server: example.net, request: "GET /wp-admin/ HTTP/1.1", upstream: "fastcgi://unix:/tmp/php-fpm.sock:", host: "example.net", referrer: "http://example.net/"
我有点失落:
我的Nginxconfiguration包含很多文件,基本的configuration是:
user ec2-user ec2-user; worker_processes 5; error_log /opt/nginx/error.log; pid /var/run/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 /opt/nginx/access.log main; sendfile on; keepalive_timeout 65; client_max_body_size 13m; index index.php index.html index.htm; upstream php { server unix:/tmp/php-fpm.sock; } include /etc/nginx/conf.d/*.conf; include /mnt/web/nginx/conf.d/*.conf; }
我的/etc/nginx/conf.d/是空的我的/mnt/web/nginx/conf.d包含很多网站configuration都包含“wordpress.conf”:
location / { try_files $uri $uri/ /index.php?$args; } rewrite /wp-admin$ $scheme://$host$uri/ permanent; location ~* \.(js|css|png|jpg|jpeg|gif|ico)$ { expires 24h; log_not_found off; } location ~ \.php$ { try_files $uri =404; fastcgi_split_path_info ^(.+\.php)(/.+)$; include fastcgi_params; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; fastcgi_pass php; }
我的/opt/php/etc/php-fpm.conf:
include=/opt/php/etc/fpm.d/*.conf pid = run/php-fpm.pid error_log = log/php-fpm.log log_level = notice [www] listen = /tmp/php-fpm.sock user = ec2-user group = ec2-user pm = dynamic pm.max_children = 250 pm.start_servers = 20 pm.min_spare_servers = 5 pm.max_spare_servers = 35 pm.max_requests = 500 pm.status_path = /fpm-status ping.path = /fpm-ping slowlog = log/$pool.log.slow catch_workers_output = yes
更新:发现问题,把它放在答案
我已经设置了/ var / lib / nginx / tmp到ec2-user / ec2-user(我甚至要检查一切+777)
但是…我还必须将/ var / lib / nginx设置为ec2-user / ec2-user
…之后还chown / chgrp父母的nginx文件夹:没有更多的错误。
花了我几个小时
这通常发生。 当nginx.conf中的user设置改变时
user nginx;
到别的东西。 在这种情况下,
user ec2-user ec2-user;
每个Chris的评论都不需要chmod命令,并且可能会打开一个安全漏洞。
解:
检查/ var / lib / nginx上的当前用户和组的所有权。
$ ls -ld /var/lib/nginx drwx------ 3 nginx nginx 4096 Aug 5 00:05 /var/lib/nginx
这告诉你一个可能不存在的用户和名为nginx组拥有这个文件夹。 这可以防止file upload。
将文件夹所有权更改为本例中的nginx.conf中定义的用户ec2-user (可能不需要sudo)。
$ sudo chown -Rf ec2-user:ec2-user /var/lib/nginx
确认它确实改变了。
$ ls -ld /var/lib/nginx drwx------ 3 ec2-user ec2-user 4096 Aug 5 00:05 /var/lib/nginx
现在许可被拒绝的错误应该消失。 检查error.log(基于nginx.conf error_log位置)。
$ sudo nano /opt/nginx/error.log
如果这不起作用,你可能需要重新加载nginx和php-fpm。
$ sudo service nginx reload $ sudo service php-fpm reload
没有其他的解决scheme为我工作,但我发现这个工作:
$ apt-get install php-pear php5-dev $ pecl install timezonedb $ echo 'extension=timezonedb.so'> /etc/php5/mods-available/timezonedb.ini $ ln -sf /etc/php5/mods-available/timezonedb.ini /etc/php5/conf.d/30-timezonedb.ini $ service php5-fpm restart
资源
我有类似的file upload问题。 nginx 500错误2015/07/05 03:50:36 [crit] 3656#0: *7 open() "/var/lib/nginx/tmp/client_body/0000000007" failed (13: Permission denied), client: 10.0.2.2, server: www.test.com, request: "POST /api/v1/users HTTP/1.1", host: "test"
这个问题只与权限有关,我只是设置了chmod -R 755 /var/lib/nginx而且工作起来了!
刚刚解决了我的权限问题。 最简单的方法和最简单的方法是不要像sudo(超级用户)那样运行php-fpm或nginx。 你将不得不做的是:
chown yourUserName:yourUserName /var/log/nginx/error.log chown yourUserName:yourUserName -R /var/www 通过不使用root我不必更改php-fpm用户或组或任何听用户或组。 确保你也注释掉了nginx.conf'user',因为它是当前用户的名字。