架构:前端两台nginx做负载,后端real server,nginx作为web服务器,还会用到apache
目的:让后端nginx的访问日志显示真实ip,以便于统计
配置:
前端:
-
server {
-
-
listen 80;
-
server_name xxx.com;
-
-
access_log /data/logs/access.log main;
-
error_log /data/logs/error.log;
-
-
location / {
-
proxy_pass http://abc_server;
-
proxy_set_header Host $host;
-
proxy_set_header X-Real-IP $remote_addr;
-
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
-
-
}
-
-
}
nginx后端:
-
http {
-
-
include mime.types;
-
-
default_type application/octet-stream;
-
-
log_format main '$http_x_forwarded_for - $remote_user [$time_local] "$request" '
-
'$status $body_bytes_sent "$http_referer" '
-
'"$http_user_agent" "$http_x_forwarded_for"'
apache后端:
http.conf中添加
-
<IfModule log_config_module>
-
#
-
# The following directives define some format nicknames for use with
-
# a CustomLog directive (see below).
-
#
-
#LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined
-
LogFormat "%{X-Forwarded-For}i %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined
-
LogFormat "%h %l %u %t \"%r\" %>s %b" common
-
CustomLog "|/soft/apache/bin/rotatelogs /data/httplogs/access.%Y%m%d 86400 +480" combined
阅读(2530) | 评论(0) | 转发(0) |