title: Nginx Load Balancer having two load balanced nginx+php-fpm (Primary script unknown) error
body: <p>We have two web servers with nginx+php-fpm ( 10.0.0.10 and 10.0.0.20 ), which is load balanced behind another nginx server ( just nginx ), when we try to browse we get file not found error, with error logs listed at the bottom.   </p>
  
  <p>Load Balancer (10.0.0.1)</p>
  
  <p>nginx.conf</p>
  
  <pre><code>upstream test_rack {
      server 10.0.0.10:80;
      server 10.0.0.20:80;
  }
  
  server {
      location / {
         proxy_pass http://test_rack;
       }
  }}
  </code></pre>
  
  <p>Upstream Server (10.0.0.20)</p>
  
  <p>subdomains.conf</p>
  
  <pre><code>server {
  listen       80;
  server_name ~^(?&lt;sub&gt;.+)\.example\.com$;
  
  root /data/vhost/$sub.example.com/htdocs;
  
  location / { 
      try_files $uri /index.php;
   }
  
  
  location ~ \.php$ {
      fastcgi_pass   unix:/var/run/php5-fpm.sock;
      fastcgi_index  index.php;
      fastcgi_param  SCRIPT_FILENAME   $document_root$fastcgi_script_name;
      include        fastcgi_params;
  }}     
  </code></pre>
  
  <p>Error on webserver (10.0.0.10 and 10.0.0.20)</p>
  
  <pre><code>*1 FastCGI sent in stderr: "Primary script unknown" while reading response header from upstream, client: 10.0.0.1, server: ~^(?&lt;sub&gt;.+)\.example\.com$, request: "GET / HTTP/1.0", upstream: "fastcgi://unix:/var/run/php5-fpm.sock:", host: "test_rack"
  </code></pre>
  
  <p>Solutions tried :</p>
  
  <pre><code>fastcgi_param  SCRIPT_FILENAME   /data/vhost/$sub.example.com/htdocs/$fastcgi_script_name;
  </code></pre>