编程语言
首页 > 编程语言> > HHVM回退到PHP-FPM

HHVM回退到PHP-FPM

作者:互联网

我在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

我在这做错了吗?

解决方法:

这可以用更简单的方式实现.

首先使用hhvm和php-fpm定义上游作为备份.

upstream fastcgi_server {
  server unix:/var/run/hhvm/hhvm.sock;
  server unix:/var/run/php-fpm-mysite.sock backup;
}

然后只使用fastcgi_server就好像是唯一的后端,nginx处理故障转移工作,而不是你.

fastcgi_pass fastcgi_server;

模块上游文档非常具有启发性.

http://nginx.org/en/docs/http/ngx_http_upstream_module.html

总结一下,您的示例如下所示:

upstream php_backend {
  server 127.0.0.1:9000;
  server unix:/var/run/php5-fpm.sock backup;
}


server {
#
# other conf...
#

 location ~ \.(hh|php)${
    fastcgi_intercept_errors on;

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

}

标签:php,nginx,hhvm
来源: https://codeday.me/bug/20190829/1762902.html