套cf的话,怎么获取用户的真实ip呢?

61次阅读

共计 1687 个字符,预计需要花费 5 分钟才能阅读完成。

我后端获取的 ip 都是 cf 的 ip。

请求头里有真实 IPset_real_ip_from 0.0.0.0/0;
set_real_ip_from ::/0;
real_ip_header X-Forwarded-For; 复制代码
丢在伪静态里 cf-connecting-ip 就是真实 ip
https://developers.cloudflare.com/fundamentals/get-started/reference/http-request-headers/https://www.yunloc.com/647.html 涨姿势,来学习下~

lonefly 发表于 2023-1-5 00:54
https://www.yunloc.com/647.html

方法 2,我把代码添加到我 /etc/nginx/nginx.conf 的 http 里面,重启出错,不能添加这个代码呢。

斌斌 发表于 2023-1-5 09:43
方法 2,我把代码添加到我 /etc/nginx/nginx.conf 的 http 里面,重启出错,不能添加这个代码呢。…

站点日志后面加上 access
access_log /www/wwwlogs/yunloc.com.log access;

lonefly 发表于 2023-1-5 10:16
站点日志后面加上 access
access_log /www/wwwlogs/yunloc.com.log access;

不是这个问题呢。是加了方法二的东西,重启 nginx 直接出错。
Job for nginx.service failed because the control process exited with error code.
See "systemctl status nginx.service" and "journalctl -xe" for details.
root@HZ1 ~ # systemctl status nginx.service
● nginx.service – A high performance web server and a reverse proxy server
Loaded: loaded (/lib/systemd/system/nginx.service; enabled; vendor preset: enabled)
Active: failed (Result: exit-code) since Thu 2023-01-05 10:32:36 CST; 6s ago
Docs: man:nginx(8)
Process: 166235 ExecStartPre=/usr/sbin/nginx -t -q -g daemon on; master_process on; (code=exited,> CPU: 5ms
Jan 05 10:32:36 HZ1 systemd[1]: Starting A high performance web server and a reverse proxy server…
Jan 05 10:32:36 HZ1 nginx[166235]: nginx: [emerg] pcre_compile() failed: unrecognized character after>Jan 05 10:32:36 HZ1 nginx[166235]: nginx: configuration file /etc/nginx/nginx.conf test failed
Jan 05 10:32:36 HZ1 systemd[1]: nginx.service: Control process exited, code=exited, status=1/FAILURE
Jan 05 10:32:36 HZ1 systemd[1]: nginx.service: Failed with result ‘exit-code’.
Jan 05 10:32:36 HZ1 systemd[1]: Failed to start A high performance web server and a reverse proxy ser>

正文完
 0