0

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.

Load Balancer (10.0.0.1)

nginx.conf

upstream test_rack {
server 10.0.0.10:80;
server 10.0.0.20:80;
}

server {
location / {
   proxy_pass http://test_rack;
 }
 }}

Upstream Server (10.0.0.20)

subdomains.conf

server {
listen       80;
server_name ~^(?<sub>.+)\.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;
}}     

Error on webserver (10.0.0.10 and 10.0.0.20)

*1 FastCGI sent in stderr: "Primary script unknown" while reading response header from upstream, client: 10.0.0.1, server: ~^(?<sub>.+)\.example\.com$, request: "GET / HTTP/1.0", upstream: "fastcgi://unix:/var/run/php5-fpm.sock:", host: "test_rack"

Solutions tried :

fastcgi_param  SCRIPT_FILENAME   /data/vhost/$sub.example.com/htdocs/$fastcgi_script_name;

1 Answers1

0

Seems like for some reason your regexp doesn't match, thus #sub isn't initialized, and this leads to an error. Try first the non-regexped server_name to see what's wrong.

drookie
  • 8,625
  • 1
  • 19
  • 29