hhxsv5 / laravel-s

LaravelS is an out-of-the-box adapter between Laravel/Lumen and Swoole.
MIT License
3.82k stars 470 forks source link

nginx代理后怎么获取客户端真实IP呢? #451

Closed ykxiao closed 1 year ago

ykxiao commented 1 year ago
  1. Your software version (Screenshot of your startup)

    Software Version
    PHP 7.4.33
    Swoole 4.5.11
    Laravel/Lumen 8.83.27
  2. Detail description about this issue(error/log)

    代理后只能获取到容器IP,获取不到真实IP

  3. Some reproducible code blocks and steps

    $clientIp = $request->header('X-Forwarded-For') ?? $request->header('X-Real-IP') ?? $request->ip();
hhxsv5 commented 1 year ago

这个要求Nginx要配置正确, 例如,你配置Nginx:proxy_set_header X-Real-IP $remote_addr; 就可以通过$request->header('X-Real-IP') 获取Nginx外层访问用户的IP

ykxiao commented 1 year ago

好的,谢谢,问题已解决。当时配置了一直在本地跑,测试环境就好了。