Swoole-src: http server,获取连接的真实ip

Created on 8 May 2018  ·  3Comments  ·  Source: swoole/swoole-src

在http server中好像用getClientInfo好像只能获取到远程客户端连接的服务器地址,而且是内网ip,我想获取远程客户端的真实ip可以吗

question

Most helpful comment

需要在代理端转发客户端的真实IP给Swoole的server

nginx+swoole配置

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

All 3 comments

需要在代理端转发客户端的真实IP给Swoole的server

nginx+swoole配置

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']

Was this page helpful?
0 / 5 - 0 ratings

Related issues

morozovsk picture morozovsk  ·  3Comments

qifengzhang007 picture qifengzhang007  ·  3Comments

apetab picture apetab  ·  4Comments

jobs-git picture jobs-git  ·  3Comments

pthreat picture pthreat  ·  3Comments