我想配置nginx,以便解析http標題並添加新的分析字符串來訪問日誌。以下是我需要的特定場景:解析和操作http標題並將它們添加到Nginx的訪問日誌中
傳入請求中包含多個IP(客戶端IP +某些代理服務器IP)的X-Forwarded-For標頭。
X-Forwarded-For = "1.2.3.4, 5.6.7.8"
這裏是log_format配置在我的nginx:
log_format main '{"timestamp":"$time_iso8601",'
'"clientIp":"$http_x_forwarded_for",'
'"conSerial":"$connection",'
'"agent":"$http_user_agent"}';
我想這裏是解析X - 轉發,對於頭和提取代理服務器的IP,並用sepearate標籤就像它添加日誌格式這:
log_format main '{"timestamp":"$time_iso8601",'
'"clientIp":"$http_x_forwarded_for",'
'"proxy": "5.6.7.8",'
'"conSerial":"$connection",'
'"agent":"$http_user_agent"}';
請注意,1.2.3.4是客戶端真正的IP和5.6.7.8是代理服務器的IP。
在此先感謝,任何幫助表示讚賞。
爲什麼不只是記錄整個標題? –