title: Yet another Nginx and PHP-FPM issue with 502 bad gateway error
body: <p>I am installing a Nginx with PHP7 server on CentOS and like a lot of users I have the 502 bad gateway issue. I read all night long pages trying to solve my issue but I still have the same issue. I will explain it here so if somebody have some idea of what is going on, I would appreciate some help :-)</p>
  
  <p>First of all the error logs from nginx and php-fpm. I use the "socket method" and I tried with the "network method" using 127.0.0.1:9000 but it didn't change anything... So I rollbacked the configuration. According to the logs, it does not seem to be an permission denied issue.</p>
  
  <p>Note: The html pages are OK, the issue only appears with php pages.</p>
  
  <p>nginx.log</p>
  
  <pre><code>2016/04/18 22:59:22 [error] 4705#0: *47 upstream sent invalid status "20 Site temporarily unavailable" while reading response header from upstream, client: 86.253.24.233, server: testvps.balusson.net, request: "GET /phpMyAdmin/ HTTP/1.1", upstream: "fastcgi://unix:/run/php-fpm/www.sock:", host: "testvps.balusson.net"
  
  
  2016/04/18 23:46:09 [error] 6115#0: *95 upstream sent invalid status "20 Site temporairement indisponible" while reading response header from upstream, client: 86.253.24.233, server: testvps.balusson.net, request: "GET /index.php HTTP/1.1", upstream: "fastcgi://unix:/run/php-fpm/www.sock:", host: "testvps.balusson.net"
  </code></pre>
  
  <p>But I don't see anything in the PHP-FPM logs</p>
  
  <pre><code>[root@vps263501 ~]# tail /var/log/php-fpm/error.log
  [18-Apr-2016 21:46:48] NOTICE: fpm is running, pid 8008
  [18-Apr-2016 21:46:48] NOTICE: ready to handle connections
  [18-Apr-2016 21:59:41] NOTICE: Terminating ...
  [18-Apr-2016 21:59:41] NOTICE: exiting, bye-bye!
  [18-Apr-2016 22:11:12] NOTICE: fpm is running, pid 2886
  [18-Apr-2016 22:11:12] NOTICE: ready to handle connections
  [18-Apr-2016 22:11:15] NOTICE: Terminating ...
  [18-Apr-2016 22:11:15] NOTICE: exiting, bye-bye!
  [18-Apr-2016 22:11:15] NOTICE: fpm is running, pid 2913
  [18-Apr-2016 22:11:15] NOTICE: ready to handle connections
  </code></pre>
  
  <p>My configuration file is quite simple:</p>
  
  <p>/etc/nginx/sites-available/maisonrt2012.conf</p>
  
  <pre><code>server {
    listen      80;
    server_name  testvps.balusson.net;
  
    root /var/www/maisonrt2012/public_html;
    index  index.html index.htm index.php;
  
      # Pass PHP scripts on to PHP-FPM
      location ~* \.php$ {
          try_files       $uri /index.php;
          fastcgi_split_path_info ^(.+\.php)(/.+)$;
          fastcgi_index   index.php;
          fastcgi_pass    unix:/run/php-fpm/www.sock;
          include         fastcgi_params;
          fastcgi_param   SCRIPT_FILENAME    $document_root$fastcgi_script_name;
          fastcgi_param   SCRIPT_NAME        $fastcgi_script_name;
      }
  
          location /phpMyAdmin {
                  root    /usr/share/;
                  index   index.html index.htm index.php;
          }
  }
  </code></pre>
  
  <p>The default.conf is set to the unix socket according to my sites-available configuration file</p>
  
  <pre><code>server {
      listen       80;
      server_name  localhost;
  
  
      location / {
          root   /usr/share/nginx/html;
          index  index.html index.htm index.php;
      }
  
  
      error_page   500 502 503 504  /50x.html;
      location = /50x.html {
          root   /usr/share/nginx/html;
      }
  
      location ~ \.php$ {
          root           /var/www/maisonrt2012/public_html/;
          fastcgi_pass   unix:/run/php-fpm/www.sock;
          fastcgi_index  index.php;
          fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
          include        fastcgi_params;
      }
  
  }
  </code></pre>
  
  <p>In the nginx.conf file, the user is specified as nginx;</p>
  
  <pre><code>user  nginx;
  worker_processes  1;
  
  error_log  /var/log/nginx/error.log warn;
  pid        /var/run/nginx.pid;
  
  
  events {
      worker_connections  1024;
  }
  </code></pre>
  
  <p>My PHP-FPM config file is as below
  /etc/php-fpm.d/www.conf</p>
  
  <pre><code>; Start a new pool named 'www'.
  [www]
  
  user = nginx
  group = nginx
  
  ;listen = 127.0.0.1:9000
  listen = /run/php-fpm/www.sock
  
  listen.owner = nginx
  listen.group = nginx
  listen.mode = 0660
  
  ;listen.acl_users = nobody
  ;listen.acl_groups =
  
  listen.allowed_clients = 127.0.0.1
  </code></pre>
  
  <p>The location of www.sock is OK with the nginx user and rights</p>
  
  <pre><code>[root@vps263501 ~]# ls -l /run/php-fpm/
  total 0
  srw-rw---- 1 nginx nginx 0 Apr 18 22:11 www.sock
  </code></pre>
  
  <p>I added the two following lines in the file /etc/nginx/fastcgi_params because they were missing (I found this on a different topic)</p>
  
  <pre><code>fastcgi_param  SCRIPT_FILENAME    $document_root$fastcgi_script_name;
  fastcgi_param  PATH_INFO          $fastcgi_script_name;
  </code></pre>
  
  <p>But I still have my issue.
  I'm stuck now so if anybody have an idea I would appreciate :-)</p>
  
  <p>Of course, PHP and Nginx are well started with the proper user</p>
  
  <pre><code>[root@vps263501 ~]# ps aux | grep php
  root      2913  0.0  0.3 317080  6464 ?        Ss   Apr18   0:00 php-fpm: master process (/etc/php-fpm.conf)
  nginx     2914  0.0  0.4 319436  8460 ?        S    Apr18   0:00 php-fpm: pool www
  nginx     2915  0.0  0.4 319436  8460 ?        S    Apr18   0:00 php-fpm: pool www
  nginx     2916  0.0  0.4 319436  8460 ?        S    Apr18   0:00 php-fpm: pool www
  nginx     2917  0.0  0.4 319436  8460 ?        S    Apr18   0:00 php-fpm: pool www
  nginx     2918  0.0  0.4 319436  8460 ?        S    Apr18   0:00 php-fpm: pool www
  nginx     3705  0.0  0.4 319436  8460 ?        S    Apr18   0:00 php-fpm: pool www
  root      9259  0.0  0.0 103304   892 pts/0    S+   00:09   0:00 grep php
  [root@vps263501 ~]# ps aux | grep nginx
  nginx     2914  0.0  0.4 319436  8460 ?        S    Apr18   0:00 php-fpm: pool www
  nginx     2915  0.0  0.4 319436  8460 ?        S    Apr18   0:00 php-fpm: pool www
  nginx     2916  0.0  0.4 319436  8460 ?        S    Apr18   0:00 php-fpm: pool www
  nginx     2917  0.0  0.4 319436  8460 ?        S    Apr18   0:00 php-fpm: pool www
  nginx     2918  0.0  0.4 319436  8460 ?        S    Apr18   0:00 php-fpm: pool www
  nginx     3705  0.0  0.4 319436  8460 ?        S    Apr18   0:00 php-fpm: pool www
  root      4168  0.0  0.1  45556  2140 ?        Ss   Apr18   0:00 nginx: master process /usr/sbin/nginx -c /etc/nginx/nginx.conf
  nginx     6115  0.0  0.1  45560  2324 ?        S    Apr18   0:00 nginx: worker process
  root      9261  0.0  0.0 103304   892 pts/0    S+   00:09   0:00 grep nginx
  </code></pre>
  
  <p>It might be trivial but I have to admit that I'm confused...
  Thanks for your help !</p>