我在nginx上运行PHP应用程序,HHVM为主,PHP-FPM为备份
这是我关于php处理的nginx配置
location ~ \.(hh|php)$ {
fastcgi_intercept_errors on;
error_page 500 501 502 503 = @fallback;
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_keep_conn on;
include fastcgi_params;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param SERVER_NAME $host;
fastcgi_pass 127.0.0.1:9000;
}
location @fallback {
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
include fastcgi_params;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param SERVER_NAME $host;
fastcgi_pass unix:/var/run/php5-fpm.sock;
}
为了测试配置,我停止了hhvm服务。通常会将请求传递给PHP-FPM并且应该返回200但是我得到502错误如下:
12296#0: *17 connect() failed (111: Connection refused) while connecting to upstream, client: 172.31.34.235, server: stylep3.com, request: "GET / HTTP/1.1", upstream: "fastcgi://127.0.0.1:9000", host:localhost
我在这里做错了什么
答案 0 :(得分:5)
这可以用更简单的方式实现。
首先使用hhvm和php-fpm作为备份来定义上游。
autowrite
然后只使用upstream fastcgi_server {
server unix:/var/run/hhvm/hhvm.sock;
server unix:/var/run/php-fpm-mysite.sock backup;
}
,好像是唯一的后端,nginx处理故障转移工作,而不是你。
fastcgi_server
模块上游文档非常具有启发性。
http://nginx.org/en/docs/http/ngx_http_upstream_module.html
总结一下,您的示例如下所示:
fastcgi_pass fastcgi_server;