我们有两个带有 nginx+php-fpm 的 Web 服务器( 10.0.0.10 和 10.0.0.20 ),它们在另一个 nginx 服务器(仅 nginx )后面进行负载平衡,当我们尝试浏览时,会出现文件未找到错误,错误日志列在底部。
负载均衡器(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)
子域名.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
似乎出于某种原因,您的正则表达式不匹配,因此 #sub 未初始化,这会导致错误。首先尝试非正则表达式的 server_name 以查看哪里出了问题。