Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

The solution of incorrect IP address in APACHE log record after using CDN

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/01 Report--

This article introduces the solution of incorrect IP address in APACHE log record after using CDN. The content is very detailed. Interested friends can use it for reference. I hope it will be helpful to you.

This paper mainly introduces the solution of incorrect IP address in APACHE log record after using CDN. Friends who need it can refer to it.

Recently, after doing APACHE log analysis and installing awstats, we have made observations in the past two days.

Report date January 2010

Date of first visit 11:04 on January 12, 2010

Latest visit date 23:59, January 13, 2010

Number of visitors, number of web pages, number of bytes of files

Browser traffic * 77 226 (2.93 visitors / visitors) 508979 (2252.11 pages / visits) 509492 (2254.38 files / visits) 13.67 G bytes (63430.28 K bytes / visitors)

Non-browser traffic * 117312 122716 736.24 M bytes

The results here are very confusing. There are 2W independent IP visits to the website through google, and the numbers shown here are very different. The number of web pages and files behind are consistent with the actual situation. After reason, it is found that the IP recorded in the apache log is incorrect, and most of them are the node addresses of cdn. The cause is obviously caused by CDN, and there has been a similar problem with reading user IP in the website daemon. You can use print_r ($_ SERVER) (PHP language) to find the real user IP. This site is $_ SERVER ['HTTP_CDN-SRC-IP']. This is the real customer IP that CDN carries (regardless of whether the user uses an agent or not). But how do you use this value in APACHE logging? I have not found the corresponding information or solution in GOOGLE and Baidu for a long time, so I have to think about it and seek it.

Take a closer look at the relevant configuration of logging in APACHE, aiming at LogFormat:

LogFormat "h l u t /" r / "> s b /" {Referer} I / "/" {User-Agent} I / "combined

I thought about how to get the% {Referer} and% {User-Agent}, which are also often used in the program, both of which are sent to the server as headers when the client sends the request. Later, I checked all the header information during the visit, as follows:

The code is as follows:

Array

(

[Cdn-Src-Ip] = > 222.44.46.58

[Accept] = > image/gif, image/jpeg, image/pjpeg, image/pjpeg, application/x-shockwave-flash, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword,/

[Accept-Language] = > zh-cn

[User-Agent] = > Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0; CIBA; .NET CLR 2.0.50727)

[Host] = > www.875.cn

[Cookie] = > _ _ utma=217127135.1188793388.1263188369.1263364666.1263368206.5; baby named http://www.bbqmw.net/qm_yeqm

_ _ utmz=217127135.1263368206.5.2.utmcsr=211.167.92.250 | utmccn= (referral) | utmcmd=referral | utmcct=/cgi-bin/awstats/awstats.pl; viewedShopsID=621; viewedShopsPP=%u6B27%u5C1A%u574A

[Accept-Encoding] = > gzip

[Via] = > 1.1 hnay40:80 (Cdn Cache Server V2.0)

[Connection] = > keep-alive

)

Of course, during rerfer, rerfer information will also appear in the header information, such as Cookie, Host, User-Agent and other information. These information are variables that can be used in the apache configuration file. Of course, Cdn-Src-Ip is the real IP of the customer I want. So it is speculated that ${Cdn-Src-Ip} should also be available in the logging format. The latter I should mean to ignore case. So come up with a solution:

Add a new logformat message

The code is as follows:

LogFormat "{Cdn-Src-Ip} I" u t / "r /" > s b / "{Referer} I /" / "{User-Agent} I /" combinedcdn

This is the solution to the incorrect IP address in the APACHE log record after using CDN. I hope the above content can be helpful to you and learn more knowledge. If you think the article is good, you can share it for more people to see.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report