问题标签 [real-ip]

For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.

0 投票
2 回答
819 浏览

amazon-web-services - AWS ELB 背后:如何从“netstat”中获取真实 IP?

我在 2 个 Linux Web 服务器前使用AWS Elastic Load Balancing (ELB)。但是(根据我的要求)我需要从 Web 服务器的角度了解真实 IP,尤其是当我使用netstat.

我需要实时知道来自每个 IP(来自 NETSTAT)的传入连接数。所以基本上在 Linux中(前面没有 ELB),下面的netstat命令完美地工作:

现在我只能看到 ELB 的内部 IP;这使整个事情变得非常困难。

请问这个有什么解决办法?谢谢。

0 投票
1 回答
1608 浏览

php - nginx真实客户端ip不工作

我安装了 nginx、php7 和 http_realip_module。

我有 1 台服务于 2 个网站的服务器。

站点 1 nginx 配置:

这会在我转储 $_SERVER['REMOTE_ADDR"] 时填充客户端的 IP 地址。

站点 1 使用 curl 连接到站点 2,就像一个简单的 api。

站点 2 nginx 配置:

我可以看到站点 2 上的脚本被调用,但是当我检查 PHP 中的 $_SERVER['REMOTE_ADDR'] 变量时,它会显示服务器的 IP 地址而不是客户端的 IP 地址。这里的 nginx 设置正确吗?

我怎样才能让它正常工作?

0 投票
3 回答
2999 浏览

nginx - nginx 允许|拒绝 $realip_remote_addr

使用 nginx,您可以允许和拒绝范围和 ips ( https://www.nginx.com/resources/admin-guide/restricting-access/ )。使用realip模块,可以将它使用的ip改成cloudflare后的真实IP。( http://nginx.org/en/docs/http/ngx_http_realip_module.html )

现在事情是这样的,我想将任何不是 Cloudflare 或 localhost 的 ip 列入黑名单。事实证明这相当困难,我尝试在设置 real_ip 模块设置之前将其放置,并且没有雪茄。

这可能吗?如果用户没有通过 cloudflare,这似乎是一个缺陷,它允许对某个虚拟主机进行更多的滥用。

有 $realip_remote_addr 变量,但我一生都无法找到一种方法来允许/拒绝使用它而不是正常的 $remote_addr。

编辑:我注意到防火墙可以帮助实现这一点。不幸的是,我真的只需要几个虚拟主机。

0 投票
3 回答
4257 浏览

nginx - 具有代理协议的 kubernetes nginx 入口以损坏的标头结束

我尝试使用代理协议在 google 容器上设置 nginx 入口(nodeport),以便可以将真实 ip 转发到后端服务,但最终导致标头损坏。

如果没有代理协议,一切都会很好。根据https://blog.mythic-beasts.com/2016/05/09/proxy-protocol-nginx-broken-header/这是由于使用了协议 v2(二进制),但 nginx 只能说 v1 . 有什么建议吗?

0 投票
1 回答
593 浏览

docker - 我可以通过“iptables”获取真实用户 ip:启用 false 吗?

"iptables": false在 docker daemon config 中的用户选项:

我使用选项运行服务--publish mode=host--mode=global类似于这种方法

但是当我X-Real-IP在我的应用程序中获取标题时,它的值是172.18.0.1但不是真正的用户 ip。

当我启动 Docker 守护程序时"iptables": false/etc/docker/daemon.json一切正常,我得到了真正的用户 ip。

但我需要设置"iptables": false为使用 Docker 保留 iptables 更改。

"iptables": false是否可以在 Docker 守护程序配置中获取真实用户 ip ?

0 投票
0 回答
131 浏览

laravel-5 - 当我获取本地主机 127.0.0.1 而不是获取客户端的真实 IP 地址时,如何在 Laravel 中修复它?

我试图通过使用获取用户IP: $request->ip(); 但这返回给我 localhost ip 127.0.0.1 这是我的代码:

*如何获取客户端或用户的真实IP地址?

0 投票
2 回答
479 浏览

ios - 有没有办法在 swift 或 ObjC 中为 IPv4 和 IPv6 发出单独的 DNS 请求

到目前为止,我所拥有的是:

}

但是永远不会调用回调。在控制台中,我收到此错误:TIC Read Status [9:0x0]: 1:57 ObjectiveC 不是我的能力,但我不得不搞砸它。任何帮助将不胜感激。

0 投票
2 回答
1218 浏览

nginx - 使用 proxy_protocol 时在 nginx 中阻止 CIDR 范围的更好方法是什么?

我在 AWS 的 ELB 后面有一小部分 nginx 实例。这个 ELB 是面向互联网的,并且使用 PROXY 协议,而不是 HTTP。

这是我的相关部分main.vhost

我正在尝试使用中的deny指令ngx_http_access_module来防止访问一系列 CIDR 块。

EG:在.confnginx 启动时加载的文件中:

并且在/etc/nginx/ip_block/目录中至少有一个文件:

但是,似乎 nginx 的deny指令只对$remote_addr变量有效,对变量无效$proxy_protocol_addr。这实际上意味着我不能同时使用deny指令和proxy_protocol在一起。

似乎该ngx_stream_realip_module模块可用于将值调整为$remote_addr$proxy_protocol_addr但是,我可用的 nginx 构建当前未配置--with-stream_realip_module构建标志。我目前正在运行1.10.3,但看起来该with-stream_realip_module标志是在构建中引入的1.11.4https://github.com/nginx/nginx/commit/fe2774a9d689fa1bf201dd0e89449e3d9e4ad926

选项 1:从源代码构建具有我需要编译的功能的 nginx 版本。

在查看deny指令的文档时,我发现了这个注释:

来自:https ://nginx.org/en/docs/http/ngx_http_access_module.html

这让我想知道是否有更好的方法来实现阻止 CIDR 范围的目标,该范围可能适用于我目前拥有的 nginx 二进制文件。

我可以尝试这样的事情:

文件conf/some_cidr_ranges_to_block.conf如下所示:

然后在我的服务器指令中,我可以执行以下操作:

选项 2:尝试使用geo指令和自定义 IP 范围 -> “国家代码”数据库来阻止流量。

我的问题:

0 投票
1 回答
934 浏览

nginx - 如何记录客户端真实 ip 和 CDN ip?

我正在为我的网站使用 cloudflare。

我遇到的问题是,在 nginx 上启用 realip 模块后,所有 CDN ip 都被替换为用户的 realip。然后当我检查 nginx 日志时,我无法确定用户是通过 CDN 连接还是直接连接到服务器。

下面是我的配置:

有什么办法可以同时保留 realip 和 CDN IP?

0 投票
1 回答
3007 浏览

varnish - 无法从 nginx/varnish 获取 real-ip 传递,总是显示 127.0.0.1

我想让真实 IP 显示在服务器/magento 中,但它一直回落到 127.0.0.1

服务器设置如下: - Varnish 监听端口 80 - Nginx 监听端口 8080 - SSL 流量被传递到端口 80 最后的网站是一个 magento 2 站点

Nginx 是 1.14.0 版本,带有-http_realip_module

我的 Nginx 服务器块如下:

我的 Nginx 访问日志 (8080access.log) 显示所有条目的 127.0.0.1 错误日志 (8080-error.log) 还显示客户端的 127.0.0.1 SSL 流量 443 日志显示实际 IP。

下面是我的 Nginx 配置输出:

configure arguments: --with-cc-opt='-g -O2 -fdebug-prefix-map=/build/nginx-FIJPpj/nginx-1.14.0=. -fstack-protector-strong -Wformat -Werror=format-security -fPIC -Wdate-time -D_FORTIFY_SOURCE=2' --with-ld-opt='-Wl,-Bsymbolic-functions -Wl,-z,relro -Wl,-z,now -fPIC' --prefix=/usr/share/nginx --conf-path=/etc/nginx/nginx.conf --http-log-path=/var/log/nginx/access.log --error-log-path=/var/log/nginx/error.log --lock-path=/var/lock/nginx.lock --pid-path=/run/nginx.pid --modules-path=/usr/lib/nginx/modules --http-client-body-temp-path=/var/lib/nginx/body --http-fastcgi-temp-path=/var/lib/nginx/fastcgi --http-proxy-temp-path=/var/lib/nginx/proxy --http-scgi-temp-path=/var/lib/nginx/scgi --http-uwsgi-temp-path=/var/lib/nginx/uwsgi --with-debug --with-pcre-jit --with-http_ssl_module --with-http_stub_status_module --with-http_realip_module --with-http_auth_request_module --with-http_v2_module --with-http_dav_module --with-http_slice_module --with-threads --with-http_addition_module --with-http_geoip_module=dynamic --with-http_gunzip_module --with-http_gzip_static_module --with-http_image_filter_module=dynamic --with-http_sub_module --with-http_xslt_module=dynamic --with-stream=dynamic --with-stream_ssl_module --with-mail=dynamic --with-mail_ssl_module

我试图将以下代码添加到 /etc/nginx/nginx.conf

并设置 req.http.X-Forwarded-For = client.ip; 到/etc/varnish/default.vcl,但由于它是一个magento特定版本的Varnish,我把它放在下面:

重新启动这两个服务后,我在日志和 Magento 2 中仍然得到相同的 127.0.0.1。

我很困惑,所以任何帮助表示赞赏!