Nginx Load Balancer有两个负载均衡的nginx + php-fpm(主要脚本未知)错误

时间:2015-01-16 07:04:44

标签: linux nginx load-balancing fastcgi php

我们有两个带有nginx + php-fpm(10.0.0.10和10.0.0.20)的web服务器,它在另一个nginx服务器(只是nginx)后面负载均衡,当我们尝试浏览时我们得到文件未找到错误,底部列出的错误日志。

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;
     }
}}

上游服务器(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;
}}     

网络服务器上的错误(10.0.0.10和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"

尝试解决方案:

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

1 个答案:

答案 0 :(得分:0)

proxy_set_header Host $host;添加到第一个nginx。

否则您的上游会获得test_rack而不是原始主机名,$sub变量为空。