VPS侦探论坛

 找回密码
 注册
查看: 5031|回复: 6

网站用了cdn怎么才能在nginx日志中显示用户的真实IP?

[复制链接]
发表于 2016-8-22 00:45:16 | 显示全部楼层 |阅读模式

网站用了百度云加速怎么才能在nginx日志中显示用户的真实IP?
美国VPS推荐: 遨游主机LinodeLOCVPS主机云搬瓦工80VPSVultr美国VPS主机中国VPS推荐: 阿里云腾讯云。LNMP付费服务(代装/问题排查)QQ 503228080
发表于 2016-8-22 09:01:29 | 显示全部楼层


在server段外面自定义一个日志格式
log_format cdn '$http_x_forwarded_for - $remote_user [$time_local] '
                    '"$request" $status $body_bytes_sent '
                    '"$http_referer" "$http_user_agent"';

修改对应虚拟机的 access_log  /home/wwwlogs/xxxx.log; 为 access_log  /home/wwwlogs/xxxx.log cdn;
重启nginx就行了
Linux下Nginx+MySQL+PHP自动安装工具:https://lnmp.org
 楼主| 发表于 2016-8-22 16:38:23 | 显示全部楼层

原帖由 licess 于 2016-8-22 09:01 发表
自定义一个日志格式
log_format cdn '$http_x_forwarded_for - $remote_user [$time_local] '
                    '"$request" $status $body_bytes_sent '
                    '"$http_referer" "$http_user_agen ...

谢谢军哥! 用了之后为什么有很多获取不到的IP  ?

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?注册

x
美国VPS推荐: 遨游主机LinodeLOCVPS主机云搬瓦工80VPSVultr美国VPS主机中国VPS推荐: 阿里云腾讯云。LNMP付费服务(代装/问题排查)QQ 503228080
发表于 2016-8-22 19:12:13 | 显示全部楼层



因为是通过cdn过啦的是用 $http_x_forwarded_for 记录ip的,没有的就不是cdn过来的,所以获取不到ip
Linux下Nginx+MySQL+PHP自动安装工具:https://lnmp.org
发表于 2017-2-20 06:36:55 | 显示全部楼层

回复 2# 的帖子


[root@xx ~]# /etc/init.d/nginx restart
Stoping nginx... nginx: [emerg] "log_format" directive is not allowed here in /usr/local/nginx/conf/cdn-ip.conf:3
failed. Use force-quit
Starting nginx... nginx (pid 1348 1347) already running.


2017/02/20 06:31:40 [emerg] 1365#0: "log_format" directive is not allowed here in /usr/local/nginx/conf/cdn-ip.conf:3  

我添加了个cong文件 然后在虚拟主机配置里引用这个conf文件,如上报错,第一次可以,后来就不行了。

军哥运维代购:http://shop63846532.taobao.com/

发表于 2017-2-20 12:33:20 | 显示全部楼层

回复 5# 的帖子


不清楚你该文件的具体内容和你include哪里了,应该是include的地方不对
发表于 2017-2-20 17:16:15 | 显示全部楼层

回复 6# 的帖子


cdn-ip.conf 这个文件里面第三行出错了,我就是把那个代码放cdn-ip.conf 文件里了原来不能共用一个 只能一个一个添加。。。

[ 本帖最后由 Mr.Lin 于 2017-2-21 03:14 编辑 ]
美国VPS推荐: 遨游主机LinodeLOCVPS主机云搬瓦工80VPSVultr美国VPS主机中国VPS推荐: 阿里云腾讯云。LNMP付费服务(代装/问题排查)QQ 503228080
您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|Archiver|VPS侦探 ( 鲁ICP备16040043号-1 )

GMT+8, 2024-9-27 19:27 , Processed in 0.027396 second(s), 17 queries .

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表