I update nginx to 1.4.7 and php to 5.5.12, After that I got the 502 error. Before I update everything works fine.
nginx-error.log
2014/05/03 13:27:41 [crit] 4202#0: *1 connect() to unix:/var/run/php5-fpm.sock failed (13: Permission denied) while connecting to upstream, client: xx.xxx.xx.xx, server: localhost, request: "GET / HTTP/1.1", upstream: "fastcgi://unix:/var/run/php5-fpm.sock:", host: "xx.xx.xx.xx"
nginx.conf
user www www;
worker_processes 1;
location / {
root /usr/home/user/public_html;
index index.php index.html index.htm;
}
location ~ [^/]\.php(/|$) {
fastcgi_split_path_info ^(.+?\.php)(/.*)$;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /usr/home/user/public_html$fastcgi_script_name;
include fastcgi_params;
}
Alternative to broadening permissions in your php config, you could change the user specified in your nginx config.
On the first line of your nginx.conf excerpt above, the user and group are specified as www and www, respectively.
Meanwhile, your php config probably specifies a user and group of www-data:
You might change the line in your nginx.conf, to any of the following, then:
I had a similar error after php update. PHP fixed a security bug where
o
hadrw
permission to the socket file./etc/php5/fpm/pool.d/www.conf
or/etc/php/7.0/fpm/pool.d/www.conf
, depending on your version.Uncomment all permission lines, like:
Restart fpm -
sudo service php5-fpm restart
orsudo service php7.0-fpm restart
Note: if your webserver runs as user other than www-data, you will need to update the
www.conf
file accordinglyI did change OS on my server quite a few times trying to get the most comfortable system.
It used to work very well most of the time but lastly I got this 502 Gateway error.
I use a php fpm socket for each account instead of keeping the same one for all. So if one crashes, at least the other applications keep running.
I used to have user and group www-data. But this changed on my Debian 8 with latest Nginx 1.8 and php5-fpm.
The default user is nginx and so is the group. To be sure of this, the best way is to check the /etc/group and /etc/passwd files. These can't lie.
It is there I found that now I have nginx in both and no longer www-data.
Maybe this can help some people still trying to find out why the error message keeps coming up.
It worked for me.
If you have declarations
and
in different configuration files, then root will owner of this file.
The problem in my case was that the Nginx web server was running as user nginx and the pool was running as user www-data.
I solved the issue by changing the user Nginx is running at in the
/etc/nginx/nginx.conf
file (could be different on your system, mine is Ubuntu 16.04.1)Change:
user nginx;
to:
user www-data;
then restart Nginx:
service nginx restart
I just got this error again today as I updated my machine (with updates for PHP) running Ubuntu 14.04. The distribution config file
/etc/php5/fpm/pool.d/www.conf
is fine and doesn't require any changes currently.I found the following errors:
The strange thing was that I have 2 sites running that utilize PHP-FPM on this machine one was running fine and the other (a Tiny Tiny RSS installation) gave me a 502, where both have been running fine before.
I compared both configuration files and found that
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
was missing for the affected site.Both configuration files now contain the following block and are running fine again:
Update
It should be noted that Ubuntu ships two fastcgi related parameter files and also a configuration snippet which is available since Vivid and also in the PPA version. The solution was updated accordingly.
Diff of the fastcgi parameter files:
Configuration snippet in
/etc/nginx/snippets/fastcgi-php.conf