nginx error connect to php5-fpm.sock failed (13: Permission denied)

后端 未结 25 1734
悲哀的现实
悲哀的现实 2020-11-27 09:12

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.

相关标签:
25条回答
  • 2020-11-27 09:24

    All the fixes currently mentioned here basically enable the security hole all over again.

    What I ended up doing is adding the following lines to my PHP-FPM configuration file.

    listen.owner = www-data
    listen.group = www-data
    

    Make sure that www-data is actually the user the nginx worker is running as. For debian it's www-data by default.

    Doing it this way does not enable the security problem that this change was supposed to fix.

    0 讨论(0)
  • 2020-11-27 09:25

    If you have declarations

    pid = /run/php-fpm.pid

    and

    listen = /run/php-fpm.pid

    in different configuration files, then root will owner of this file.

    0 讨论(0)
  • 2020-11-27 09:26

    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:

    dmesg | grep php
    [...]
    [ 4996.801789] traps: php5-fpm[23231] general protection ip:6c60d1 sp:7fff3f8c68f0 error:0 in php5-fpm[400000+800000]
    [ 6788.335355] traps: php5-fpm[9069] general protection ip:6c5d81 sp:7fff98dd9a00 error:0 in php5-fpm[400000+7ff000]
    

    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:

    location ~ \.php$ {
            fastcgi_pass unix:/var/run/php5-fpm.sock;
            include /etc/nginx/snippets/fastcgi-php.conf;
    }
    

    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:

    $ diff -up fastcgi_params fastcgi.conf
    --- fastcgi_params      2015-07-22 01:42:39.000000000 +0200
    +++ fastcgi.conf        2015-07-22 01:42:39.000000000 +0200
    @@ -1,4 +1,5 @@
    
    +fastcgi_param  SCRIPT_FILENAME    $document_root$fastcgi_script_name;
     fastcgi_param  QUERY_STRING       $query_string;
     fastcgi_param  REQUEST_METHOD     $request_method;
     fastcgi_param  CONTENT_TYPE       $content_type;
    

    Configuration snippet in /etc/nginx/snippets/fastcgi-php.conf

    # regex to split $uri to $fastcgi_script_name and $fastcgi_path
    fastcgi_split_path_info ^(.+\.php)(/.+)$;
    
    # Check that the PHP script exists before passing it
    try_files $fastcgi_script_name =404;
    
    # Bypass the fact that try_files resets $fastcgi_path_info
    # see: http://trac.nginx.org/nginx/ticket/321
    set $path_info $fastcgi_path_info;
    fastcgi_param PATH_INFO $path_info;
    
    fastcgi_index index.php;
    include fastcgi.conf;
    
    0 讨论(0)
  • 2020-11-27 09:26

    I have fixed same issue on Amazon Linux AMI 2016.09 (Centos 7) by taking following steps.

    Open your www.conf files (Example : sudo nano /etc/php-fpm.d/www.conf) Lastly, find the lines that set the listen.owner and listen.group and change their values from "nobody" to "nginx":

    listen.owner = nginx
    listen.group = nginx
    listen.mode = 0666
    

    Lastly, find the lines that set the user and group and change their values from "apache" to "nginx":

    user = nginx
    group = nginx
    

    Restart php-fpm (sudo service php-fpm restart)

    0 讨论(0)
  • 2020-11-27 09:26

    I had the similar error.

    All recommendations didn't help.

    The only replacement www-data with nginx has helped:

    $ sudo chmod nginx:nginx /var/run/php/php7.2-fpm.sock
    

    /var/www/php/fpm/pool.d/www.conf

    user = nginx
    group = nginx
    ...
    listen.owner = nginx
    listen.group = nginx
    listen.mode = 0660
    
    0 讨论(0)
  • 2020-11-27 09:27

    If you have different pool per user make sure user and group are set correctly in configuration file. You can find nginx user in /etc/nginx/nginx.conf file. nginx group is same as nginx user.

    user = [pool-user]
    group = [pool-group]
    listen.owner = [nginx-user]
    listen.group = [nginx-group]
    
    0 讨论(0)
提交回复
热议问题