laruence / yaf

Fast php framework written in c, built in php extension
http://pecl.php.net/package/yaf
Other
4.52k stars 1.37k forks source link

解决官网手册Nginx配置错误导致死循环PHP502 500报错 #552

Open letwang opened 3 years ago

letwang commented 3 years ago

https://github.com/letwang/HookPHP 在使用Yaf2.0+版本时没有问题,很完美,根据官网手册配置的:https://www.php.net/manual/en/yaf.tutorials.php#example-3855

但是自从HookPHP升级到PHP8 + Yaf3.3.3版本,就报错了导致Nginx死循环 PHP报502 500错误:

2021/08/08 03:29:47 [error] 6188#6188: *2 rewrite or internal redirection cycle while processing "/index.phpindex.phpindex.phpindex.phpindex.phpindex.phpindex.phpindex.phpindex.phpindex.phpindex.phpindex.phprbac_group", client: 172.17.0.1, server: www.admin.com, request: "GET /rbac_group HTTP/2.0", host: "www.admin.com:81", referrer: "https://www.admin.com:81/"

解决: Example #3 Rewrite rule

for nginx

server {
  listen ****;
  server_name  domain.com;
  root   document_root;
  index  index.php index.html index.htm;

  if (!-e $request_filename) {
    rewrite ^/(.*)  /index.php?$1 last;
  }
}

唯一的变化,是 多出1个 ?问号

80boys commented 3 years ago

可有可无

jingjingxyk commented 4 months ago

关键地方是 调用 fastcgi 是缺少 PATH_INFO 信息


        if (!-e $request_filename) {
            rewrite ^/(.*)  /index.php?$1 last;
        }

        # 关键点: 
        location ~ ^/index\.php(/|$) { 
            # fastcgi_index   index.php;
            fastcgi_pass    127.0.0.1:9000;
            # fastcgi_pass  /var/run/php-fpm.sock ;

            fastcgi_split_path_info ^(.+\.php)(/.*)$;
            fastcgi_param PATH_INFO $fastcgi_path_info;

            include         fastcgi_params;
            fastcgi_param   SCRIPT_FILENAME    $document_root$fastcgi_script_name;
            fastcgi_param   SCRIPT_NAME        $fastcgi_script_name;
            fastcgi_hide_header X-Powered-By;
        }