最近在查看网站的`访问日志`
看到各种的搞事情
各类爬虫以及注入工具对网站进行各种尝试
在`nginx日志`怎么查看网友的`真实的ip`呢?
因为使用了`cdn`,默认记录的是cdn的`节点ip`
方法,在`nginx.conf`中添加
```
http {
include mime.types;
default_type application/octet-stream;
log_format main '"$http_x_forwarded_for" "$clientRealIp" - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" cdn节点ip->$remote_addr ';
```
然后在网站的nginx配置文件中如
`www.yuanchengzhushou.cn.conf`中添加
```
server {
listen 443;
ssl on;
ssl_certificate www.yuanchengzhushou.cn.crt; #证书
ssl_certificate_key www.yuanchengzhushou.cn.key; #私钥
server_name www.yuanchengzhushou.cn;
root "/var/www/html/lnmpdev/public";
access_log /usr/local/nginx/logs/www.lnmpdev.com.log main;
error_log /usr/local/nginx/logs/www.lnmpdev.com.error.log;
```
这样就成功的记录网友的真实访问ip
```
[root@iZbp1fna7ky0qz2jbj7gfpZ conf]# tail -f /usr/local/nginx/logs/www.lnmpdev.com.log
"117.143.124.115" "117.143.124.115" - - [20/Apr/2021:23:06:08 +0800] "GET /article/8185.html HTTP/1.1" 200 7478 "https://www.yuanchengzhushou.cn/tag/redis" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/89.0.4389.114 Safari/537.36" 61.151.164.63
"117.143.124.115" "117.143.124.115" - - [20/Apr/2021:23:06:41 +0800] "GET /article/8120.html HTTP/1.1" 200 7063 "https://www.yuanchengzhushou.cn/article/8185.html" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/89.0.4389.114 Safari/537.36" "cdn节点ip" 101.89.34.214
"117.143.124.115" "117.143.124.115" - - [20/Apr/2021:23:07:10 +0800] "GET /article/8176.html HTTP/1.1" 200 6999 "https://www.yuanchengzhushou.cn/article/8120.html" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/89.0.4389.114 Safari/537.36" cdn节点ip-> 59.36.117.183
"117.143.124.115" "117.143.124.115" - - [20/Apr/2021:23:07:52 +0800] "GET /article/8001.html HTTP/1.1" 200 7150 "https://www.yuanchengzhushou.cn/article/8176.html" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/89.0.4389.114 Safari/537.36" cdn节点ip->58.251.121.93
"117.143.124.115" "117.143.124.115" - - [20/Apr/2021:23:08:21 +0800] "GET /article/8087.html HTTP/1.1" 200 7010 "https://www.yuanchengzhushou.cn/article/8176.html" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/89.0.4389.114 Safari/537.36" cdn节点ip->58.251.121.93
"117.143.124.115" "117.143.124.115" - - [20/Apr/2021:23:08:22 +0800] "GET /complex.mp4 HTTP/1.1" 206 23101 "https://www.yuanchengzhushou.cn/article/8087.html" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/89.0.4389.114 Safari/537.36" cdn节点ip->58.251.121.93
"117.143.124.115" "117.143.124.115" - - [20/Apr/2021:23:08:22 +0800] "GET /complex.mp4 HTTP/1.1" 206 163499 "https://www.yuanchengzhushou.cn/article/8087.html" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/89.0.4389.114 Safari/537.36" cdn节点ip->58.251.121.93
"117.143.124.115" "117.143.124.115" - - [20/Apr/2021:23:08:37 +0800] "GET /article/7831.html HTTP/1.1" 200 7254 "https://www.yuanchengzhushou.cn/article/8087.html" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/89.0.4389.114 Safari/537.36" cdn节点ip->101.91.24.37
"117.143.124.115" "117.143.124.115" - - [20/Apr/2021:23:10:03 +0800] "GET / HTTP/1.1" 200 70627 "https://www.yuanchengzhushou.cn/article/7831.html" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/89.0.4389.114 Safari/537.36" cdn节点ip->116.128.128.91
"117.143.124.115" "117.143.124.115" - - [20/Apr/2021:23:10:05 +0800] "GET /article/8192.html HTTP/1.1" 200 7433 "https://www.yuanchengzhushou.cn/" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/89.0.4389.114 Safari/537.36" cdn节点ip->223.166.151.125
```