让nginx后端访问日志显示真实ip

2600阅读 0评论2014-10-10 davie5201314
分类:系统运维

架构:前端两台nginx做负载,后端real server,nginx作为web服务器,还会用到apache
目的:让后端nginx的访问日志显示真实ip,以便于统计
配置:
    前端:
  1. server {

  2.         listen 80;
  3.         server_name xxx.com;

  4.         access_log /data/logs/access.log main;
  5.         error_log /data/logs/error.log;

  6.         location / {
  7.             proxy_pass http://abc_server;
  8.             proxy_set_header Host $host;
  9.             proxy_set_header X-Real-IP $remote_addr;
  10.             proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

  11.         }

  12.     }
    nginx后端:
  1. http {

  2.     include mime.types;

  3.     default_type application/octet-stream;

  4.     log_format main '$http_x_forwarded_for - $remote_user [$time_local] "$request" '
  5.                       '$status $body_bytes_sent "$http_referer" '
  6.                       '"$http_user_agent" "$http_x_forwarded_for"'
apache后端:
http.conf中添加

  1. <IfModule log_config_module>
  2.     #
  3.     # The following directives define some format nicknames for use with
  4.     # a CustomLog directive (see below).
  5.     #
  6.     #LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined
  7.     LogFormat "%{X-Forwarded-For}i %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined
  8.     LogFormat "%h %l %u %t \"%r\" %>s %b" common

  1. CustomLog "|/soft/apache/bin/rotatelogs /data/httplogs/access.%Y%m%d 86400 +480" combined


上一篇:zabbix用默认模板监控cpu负载问题
下一篇:nagios监控失败报错It appears as though you do not have..