swoft-cloud / swoft

🚀 PHP Microservice Full Coroutine Framework
https://swoft.org
Apache License 2.0
5.58k stars 788 forks source link

nginx代理后onMessage获取不到真实地址(已尝试各种方法) #473

Closed ghost closed 5 years ago

ghost commented 5 years ago
Q A
Bug report? yes/no
Feature request? yes/no
Swoft version 最新版
Swoole version 4.2.7 (by php --ri swoole)
PHP version 7.2 (by php -v)
Runtime environment CentOS 7

Details 经过nginx代理转发后,即便配置了remote_ip等参数, $server->getClientInfo($frame->fd)['remote_ip'] 获取到的IP地址依旧是127.0.0.1,所有$server参数都看过了。。。获取不了,麻烦帮忙看看!

ghost commented 5 years ago

修改nginx.conf之类的各种方式都已试过! onOpen 事件的Request $request 可以通过 获取其他request参数得到nginx转发的IP,onMessage没有API

longjianghu commented 5 years ago

检查一下nginx配置文件,如果要获取IP需要进行相应的配置。

inhere commented 5 years ago

@cailetech

WebSocketContext:getRequest() 可以拿到open时的request对象

https://github.com/swoft-cloud/swoft-component/blob/master/src/websocket-server/src/WebSocketContext.php#L165