title: Nginx 502 Bad Gateway - Permission denied
body: <p>I've been searching the Google for the last day or so and tried several solutions. I don't know what could be causing this error. The following may be long, I apologize -- I'm trying to anticipate some common responses to try to help diagnosis the problem :)</p>
  
  <pre><code>2014/05/11 17:26:00 [crit] 29833#0: *31 connect() to unix:/var/run/php/default.sock failed (13: Permission denied) 
  </code></pre>
  
  <p>-</p>
  
  <h3>My vhost config is:</h3>
  
  <pre><code>server {
          server_name             .lone0001.ca;
          listen                  80;
  
          root            /home/lone0001/public_html;
          error_log       /home/lone0001/.nginx/logs/error.log;
          access_log      /home/lone0001/.nginx/logs/access.log;
  
          include         /etc/nginx/includes/global/robots.conf;
          include         /etc/nginx/includes/global/wordpress.conf;
          include         /etc/nginx/includes/lone0001_php.conf;
  }
  </code></pre>
  
  <h3>The PHP configuration (an include) is thus:</h3>
  
  <pre><code>location ~ \.php$ {
          try_files               $uri =404;
          fastcgi_split_path_info ^(.+\.php)(/.+)$;
          include                 /etc/nginx/includes/global/fastcgi_params;
  
          fastcgi_index           index.php;
          fastcgi_param           SCRIPT_FILENAME         $document_root$fastcgi_script_name;
  
          fastcgi_pass    unix:/var/run/php/lone0001.sock;
  }
  </code></pre>
  
  <h3>Now, my php fpm pool configuration has the following (abbreviated):</h3>
  
  <p><strong>"lone0001.conf":</strong></p>
  
  <pre><code>[lone0001]
  user = lone0001
  group = lone0001
  
  listen = /var/run/php/lone0001.sock
  
  listen.owner = lone0001
  listen.group = lone0001
  listen.mode = 0666
  </code></pre>
  
  <p><strong>"www.conf":</strong></p>
  
  <pre><code>[www]
  user = www-data
  group = www-data
  listen = /var/run/php/default.sock
  listen.owner = www-data
  listen.group = www-data
  listen.mode = 0666
  </code></pre>
  
  <h3>File permissions you may ask?</h3>
  
  <pre><code>superuser@myserver:/etc/php5/fpm/pool.d# ls -l /var/run/php/
  total 0
  srwxrwxr-- 1 www-data    www-data    0 May 11 17:21 default.sock
  srwxrwxr-- 1 lone0001    lone0001    0 May 11 17:21 lone0001.sock
  </code></pre>
  
  <h3>Some notes:</h3>
  
  <p>I have tried <code>chmod -Rf 0666 /var/run/php</code> and I've tried moving the PHP sockets to <code>/tmp</code> (no success). I also tried switching my vhost to my "default" PHP socket to no avail.</p>