在http server中好像用getClientInfo好像只能获取到远程客户端连接的服务器地址,而且是内网ip,我想获取远程客户端的真实ip可以吗
需要在代理端转发客户端的真实IP给Swoole的server
server {
root /data/wwwroot/;
server_name local.swoole.com;
location / {
proxy_http_version 1.1;
proxy_set_header Connection "keep-alive";
proxy_set_header X-Real-IP $remote_addr; #here
if (!-e $request_filename) {
proxy_pass http://127.0.0.1:9501;
}
}
}
在swoole中通过读取$request->header['x-real-ip']来获取客户端的真实IP
@twose 我只是用了swoole,没有用nginx进行转发到swoole上,是不是就获取不到了呢
从请求实例中获取: $request->server['remote_addr']
Most helpful comment
需要在代理端转发客户端的真实IP给Swoole的server
nginx+swoole配置
在swoole中通过读取
$request->header['x-real-ip']来获取客户端的真实IP