Chinaunix首页 | 论坛 | 博客
  • 博客访问: 327589
  • 博文数量: 61
  • 博客积分: 365
  • 博客等级: 一等列兵
  • 技术积分: 611
  • 用 户 组: 普通用户
  • 注册时间: 2009-12-04 11:39
文章分类

全部博文(61)

文章存档

2017年(15)

2016年(13)

2015年(19)

2014年(12)

2013年(2)

我的朋友

分类: 系统运维

2014-10-10 08:53:12

架构:前端两台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


阅读(2547) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~