Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

phpwebstudy2.0.0 + nginx + php8.2 post提交就会报502 #71

Closed
classic-up opened this issue Feb 21, 2024 · 17 comments
Closed

phpwebstudy2.0.0 + nginx + php8.2 post提交就会报502 #71

classic-up opened this issue Feb 21, 2024 · 17 comments

Comments

@classic-up
Copy link

我安装了最新版phpwebstudy2.0.0
在phpwebstudy内安装了nginx
在phpwebstudy内安装了PHP8.2
phpwebstudy内redis使用7版本,安装并复制连接添加到php配置文件内

我是有phpwebstudy配置了两个站点,其中一个使用php7.3,运行起来完全没有问题
另一个PHP8.2的站点,正常get访问没有问题,但是当我需要post提交表单数据就会502,当我频繁刷新的情况下,可能会出现成功的情况,但是大部分post提交表单情况下都是502

下面是遇到502情况的日志,希望能帮助解决问题

站点日志
2024/02/21 13:12:38 [error] 51852#0: *6 upstream prematurely closed connection while reading response header from upstream, client: 127.0.0.1, server: 127.0.0.1, request: "POST /teachers/login HTTP/1.1", upstream: "fastcgi://unix:/tmp/phpwebstudy-php-cgi-82.sock:", host: "127.0.0.1", referrer: "http://127.0.0.1/teachers/login"
2024/02/21 13:12:38 [error] 51852#0: *6 upstream prematurely closed connection while reading response header from upstream, client: 127.0.0.1, server: 127.0.0.1, request: "POST /teachers/login HTTP/1.1", upstream: "fastcgi://unix:/tmp/phpwebstudy-php-cgi-82.sock:", host: "127.0.0.1", referrer: "http://127.0.0.1/teachers/login"

php日志
[21-Feb-2024 13:12:38] NOTICE: [pool www] child 51941 started
[21-Feb-2024 13:12:38] WARNING: [pool www] child 51939 exited on signal 11 (SIGSEGV) after 0.657027 seconds from start
[21-Feb-2024 13:12:38] NOTICE: [pool www] child 51942 started
[21-Feb-2024 13:12:38] WARNING: [pool www] child 51940 exited on signal 11 (SIGSEGV) after 0.640433 seconds from start
[21-Feb-2024 13:12:38] NOTICE: [pool www] child 51943 started
[21-Feb-2024 13:12:38] WARNING: [pool www] child 51941 exited on signal 11 (SIGSEGV) after 0.641604 seconds from start
[21-Feb-2024 13:12:38] NOTICE: [pool www] child 51944 started

@xpf0000
Copy link
Owner

xpf0000 commented Feb 21, 2024

redis扩展各个PHP版本不通用, php7.3安装扩展了, php8.2也需要安装并把扩展链接添加到php8.2的配置文件中
添加完重启php服务再试下

@xpf0000
Copy link
Owner

xpf0000 commented Feb 21, 2024

如果你php7.3 不是通过phpwebstudy安装的, 可以看下php7.3的配置文件, 看下和8.2的有啥区别, 把8.2修改成和7.3一样的再试下

@classic-up
Copy link
Author

扩展都是单独安装的,所有的php版本都是从phpwebstudy安装的。

@xpf0000
Copy link
Owner

xpf0000 commented Feb 21, 2024

nginx日志和redis日志也发出来看下

@classic-up
Copy link
Author

完成get请求与post请求时的日志

nginx-access日志
127.0.0.1 - - [21/Feb/2024:14:25:34 +0800] "GET / HTTP/1.1" 200 159952 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/121.0.0.0 Safari/537.36"
127.0.0.1 - - [21/Feb/2024:14:25:37 +0800] "GET /teachers/login HTTP/1.1" 200 39053 "http://127.0.0.1/" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/121.0.0.0 Safari/537.36"
127.0.0.1 - - [21/Feb/2024:14:25:41 +0800] "POST /teachers/login HTTP/1.1" 502 559 "http://127.0.0.1/teachers/login" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/121.0.0.0 Safari/537.36"

redis日志
49918:M 21 Feb 2024 14:27:03.024 - DB 0: 3 keys (1 volatile) in 4 slots HT.
49918:M 21 Feb 2024 14:27:03.025 . 0 clients connected (0 replicas), 1272496 bytes in use
49918:M 21 Feb 2024 14:27:08.097 - DB 0: 3 keys (1 volatile) in 4 slots HT.
49918:M 21 Feb 2024 14:27:08.098 . 0 clients connected (0 replicas), 1272496 bytes in use
49918:M 21 Feb 2024 14:27:09.237 - Accepted 127.0.0.1:60168
49918:M 21 Feb 2024 14:27:09.364 - Client closed connection id=97 addr=127.0.0.1:60168 laddr=127.0.0.1:6379 fd=8 name= age=0 idle=0 flags=N db=0 sub=0 psub=0 ssub=0 multi=-1 qbuf=0 qbuf-free=16890 argv-mem=0 multi-mem=0 rbs=16384 rbp=0 obl=0 oll=0 omem=0 tot-mem=34064 events=r cmd=NULL user=default redir=-1 resp=2 lib-name= lib-ver=
49918:M 21 Feb 2024 14:27:13.169 - DB 0: 3 keys (1 volatile) in 4 slots HT.
49918:M 21 Feb 2024 14:27:13.170 . 0 clients connected (0 replicas), 1272496 bytes in use

@xpf0000
Copy link
Owner

xpf0000 commented Feb 21, 2024

可以试下其他php版本, 如果同样的php配置, 其他版本没问题, 可能是php8.2或者php8.2对应的redis扩展的bug, 等后续php版本升级后再试下吧.
redis在php8.2貌似是有bug, php-fpm使用unix端口启动时是会有问题
php/php-src#10406
PHP官方的issues

@xpf0000
Copy link
Owner

xpf0000 commented Feb 21, 2024

可以尝试使用TCP Sockets试下
~/Library/PhpWebStudy/server/php/82/conf/php-fpm.conf
修改 listen 为 127.0.0.1:9000
~/Library/PhpWebStudy/server/nginx/common/conf/enable-php-82.conf
修改 fastcgi_pass 为 127.0.0.1:9000;
然后重启 php和nginx 再试下

@classic-up
Copy link
Author

我的项目最低要求PHP8.1,我试过8.1,一样的问题。
更换listen后,也是一样的问题
2024/02/21 15:03:11 [error] 82069#0: *2 kevent() reported about an closed connection (54: Connection reset by peer) while reading response header from upstream, client: 127.0.0.1, server: 127.0.0.1, request: "POST /kaiqiang/teacher/group/create HTTP/1.1", upstream: "fastcgi://127.0.0.1:9000", host: "127.0.0.1",

@xpf0000
Copy link
Owner

xpf0000 commented Feb 21, 2024

php扩展里安装有两种方式, 默认方式的扩展, 可能版本不是最新的, 可以尝试安装homebrew或者macports
打开扩展文件夹, 删除redis.so, 然后安装homebrew或者macports版本的扩展, 然后再试下

@xpf0000
Copy link
Owner

xpf0000 commented Feb 21, 2024

我本地新建的测试项目 TP8.0, 测试了php8.1, php8.2, php8.3, php8.4, redis没啥问题
只是简单的测试

<?php

namespace app\controller;

use app\BaseController;

class Index extends BaseController
{
    public function index()
    {
        $redis = new \Redis();
        $redis->connect('127.0.0.1', 6379);
        $redis->set('a', '555');
        $v = $redis->get('a');
        return "SUCCESS !!!".$v;
    }
}

考虑是你代码层面的问题, php8和php7有些代码还是有区别的, 追踪下代码执行吧, 看看执行到哪里会导致php-fpm崩溃重启

@classic-up
Copy link
Author

我在代码入口die,依然会出现502的

@classic-up
Copy link
Author

我的项目在另一台windows上可以正常运行的

@xpf0000
Copy link
Owner

xpf0000 commented Feb 21, 2024

laravel/valet#1433 (comment)
试试这个
/opt/homebrew/etc/php/8.2/php-fpm.d/www.conf 文件里 添加

env['PGGSSENCMODE'] = disable
env['LC_ALL'] = C

然后重启PHP试试

@classic-up
Copy link
Author

依然会提示502

@HelplessMan
Copy link

依然会提示502

是不是开启了clash了。例如 你开启clash 设置了系统代理就会这样。 我开启clash有时候可以 有时候就会502。

@HelplessMan
Copy link

出现这种问题... 一般重启就好了...

@xpf0000 大佬 看能否解决一下这个问题? 就是我clash是经常开的。 好像有时候切换节点了。 在使用的话就会出现502, 我关闭系统代理 就恢复了。 在或者我重启电脑 也正常了。

@xpf0000
Copy link
Owner

xpf0000 commented Feb 26, 2024

出现这种问题... 一般重启就好了...

@xpf0000 大佬 看能否解决一下这个问题? 就是我clash是经常开的。 好像有时候切换节点了。 在使用的话就会出现502, 我关闭系统代理 就恢复了。 在或者我重启电脑 也正常了。

问题出现原因是: 如果是使用域名的话, 咱们的软件是把域名信息写入到本机系统的/etc/hosts中的, 没用VPN的话, 请求都走本地网络, 会查询/etc/hosts, 然后就可以正常解析. 但是使用VPN, 做的是VPN的隧穿网络, 远端服务器肯定没有这些域名信息, 自然就502了.

所以这个问题通过软件基本无解, 只能是关闭VPN, 或者使用IP访问

@xpf0000 xpf0000 closed this as completed May 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants