我使用的workerman版本是v5.0.0-beta.7
我也按照官方文档去配置了nginx,参考https://www.workerman.net/doc/workerman/faq/get-real-ip-from-proxy.html
还是获取不到客户端ip,求大神指点,
我在onconnect事件中打印server没有看到客户端ip
{"SHELL":"\/bin\/bash","PWD":"\/www\/wwwroot\/xxxxx","LOGNAME":"www","XDG_SESSION_TYPE":"tty","MOTD_SHOWN":"pam","HOME":"\/home\/www","LANG":"C.UTF-8","SSH_CONNECTION":"127.0.0.1 52494 127.0.0.1 22","XDG_SESSION_CLASS":"user","TERM":"xterm","USER":"www","SHLVL":"1","XDG_SESSION_ID":"27693","XDG_RUNTIME_DIR":"\/run\/user\/1001","SSH_CLIENT":"127.0.0.1 52494 22","PATH":"\/usr\/local\/bin:\/usr\/bin:\/bin:\/usr\/local\/games:\/usr\/games","DBUS_SESSION_BUS_ADDRESS":"unix:path=\/run\/user\/1001\/bus","SSH_TTY":"\/dev\/pts\/0","OLDPWD":"\/www\/wwwroot\/xxxxx\/public","_":"\/usr\/bin\/nohup","PHP_SELF":"\/www\/wwwroot\/xxxxx\/bin\/app","SCRIPT_NAME":"\/www\/wwwroot\/xxxxx\/bin\/app","SCRIPT_FILENAME":"\/www\/wwwroot\/xxxxx\/bin\/app","PATH_TRANSLATED":"\/www\/wwwroot\/xxxxx\/bin\/app","DOCUMENT_ROOT":"","REQUEST_TIME_FLOAT":1705288652.964284,"REQUEST_TIME":1705288652,"argv":["\/www\/wwwroot\/xxxxx\/bin\/app","\/workerman\/chat\/index","port=2345","start"],"argc":4}
onConnect代表TCP三次握手成功,这时还没收到任何消息,包括http头,所以onConnect里获取不到http头中传递的ip。
如果是websocket协议,要在onWebSocketConnect获取http头中的ip。
如果是http协议,在onMessage里获取获取http头中的ip
可以获取到了