![](/img/trans.png)
[英]laravel websocket with nuxt and nginx reverse proxy returns 502
[英]Get real user ip of Nuxt application through apache reverse proxy in Laravel
我使用 Nuxtjs 作为我的应用程序的前端,使用 Laravel 框架作为后端。 我在 Apache Centos 服务器上托管了我的应用程序。 在 localhost:3000 上使用 pm2 运行应用程序后,我无法在 Laravel 中获得用户的真实 IP。
我的 Centos 版本:
Operating System: CentOS Linux 7 (Core)
CPE OS Name: cpe:/o:centos:centos:7
Kernel: Linux 3.10.0-1127.10.1.el7.x86_64
Architecture: x86-64
我的 Apache 版本:
Server version: Apache/2.4.43 (Unix)
我在 apache 中的 VirtualHost:
<VirtualHost MY_IP:80>
UserDir public_html
DocumentRoot /var/www/html
ServerName example.com
ProxyPreserveHost On
RemoteIPHeader X-Forwarded-For
RemoteIPProxiesHeader X-Forwarded-By
<LocationMatch "/">
allow from all
Satisfy any
AllowOverride All
Require all granted
ProxyPass http://localhost:3000/
ProxyPassReverse http://localhost:3000/
</LocationMatch>
</VirtualHost>
我在 Laravel AppServiceProvider
中的boot
方法
public function boot()
{
Request::setTrustedProxies(['REMOTE_ADDR'], Request::HEADER_X_FORWARDED_FOR);
}
但是在这些步骤之后,当我在 Laravel 中使用request()->ip()
或request()->getClientIp()
时,它给了我服务器 ip。 如何在我的 Laravel 应用程序中获得真实的用户 ip?
也许您正在寻找的 HTTP_X_FORWARDED_FOR http 标头变量。
$_SERVER['HTTP_X_FORWARDED_FOR']
或者
$_SERVER["HTTP_X_REAL_IP"]
如果它不存在 Apache 的mod_remoteip模块可以帮助这个头变量更多关于: https : //www.globo.tech/learning-center/x-forwarded-for-ip-apache-web-server/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.