From 68d3c1030e9444ee2fafb2e5694d1d8e513bbe6f Mon Sep 17 00:00:00 2001 From: CrazyMax Date: Sat, 13 Apr 2019 02:47:24 +0200 Subject: [PATCH] Add LOG_IP_VAR environment variable (Issue #22) --- CHANGELOG.md | 4 ++++ README.md | 1 + assets/tpls/etc/nginx/nginx.conf | 7 ++++++- entrypoint.sh | 2 ++ examples/compose/librenms.env | 1 + 5 files changed, 14 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3d0419d..89156ff 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Changelog +## 1.50-RC4 (2019/04/13) + +* Add `LOG_IP_VAR` environment variable (Issue #22) + ## 1.50-RC3 (2019/04/07) * Use python3 for snmp-scan (Issue #25) diff --git a/README.md b/README.md index a4fa3c6..aa7abc9 100644 --- a/README.md +++ b/README.md @@ -50,6 +50,7 @@ It's a fork of [CrazyMax's LibreNMS Docker image repository](https://github.com/ * `OPCACHE_MEM_SIZE` : PHP OpCache memory consumption (default `128`) * `REAL_IP_FROM` : Trusted addresses that are known to send correct replacement addresses (default `0.0.0.0/32`) * `REAL_IP_HEADER` : Request header field whose value will be used to replace the client address (default `X-Forwarded-For`) +* `LOG_IP_VAR` : Use another variable to retrieve the remote IP address in Nginx. If you use a reverse proxy you can set `http_x_forwarded_for` example. (default `remote_addr`) #### (Distributed) Poller diff --git a/assets/tpls/etc/nginx/nginx.conf b/assets/tpls/etc/nginx/nginx.conf index ea57a09..f84cf91 100644 --- a/assets/tpls/etc/nginx/nginx.conf +++ b/assets/tpls/etc/nginx/nginx.conf @@ -14,7 +14,6 @@ events { http { include mime.types; default_type application/octet-stream; - access_log /proc/1/fd/1; aio threads; sendfile on; @@ -33,6 +32,12 @@ http { set_real_ip_from @REAL_IP_FROM@; real_ip_header @REAL_IP_HEADER@; + # Log + log_format main '$@LOG_IP_VAR@ - $remote_user [$time_local] ' + '"$request" $status $body_bytes_sent ' + '"$http_referer" "$http_user_agent"'; + access_log /proc/1/fd/1 main; + ## Hide the Nginx version number server_tokens off; diff --git a/entrypoint.sh b/entrypoint.sh index 6e22e98..b4b9d93 100644 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -13,6 +13,7 @@ UPLOAD_MAX_SIZE=${UPLOAD_MAX_SIZE:-16M} OPCACHE_MEM_SIZE=${OPCACHE_MEM_SIZE:-128} REAL_IP_FROM=${REAL_IP_FROM:-"0.0.0.0/32"} REAL_IP_HEADER=${REAL_IP_HEADER:-"X-Forwarded-For"} +LOG_IP_VAR=${LOG_IP_VAR:-remote_addr} MEMCACHED_PORT=${MEMCACHED_PORT:-11211} RRDCACHED_PORT=${RRDCACHED_PORT:-42217} @@ -98,6 +99,7 @@ echo "Setting Nginx configuration..." sed -e "s#@UPLOAD_MAX_SIZE@#$UPLOAD_MAX_SIZE#g" \ -e "s#@REAL_IP_FROM@#$REAL_IP_FROM#g" \ -e "s#@REAL_IP_HEADER@#$REAL_IP_HEADER#g" \ + -e "s#@LOG_IP_VAR@#$LOG_IP_VAR#g" \ /tpls/etc/nginx/nginx.conf > /etc/nginx/nginx.conf # SNMP diff --git a/examples/compose/librenms.env b/examples/compose/librenms.env index 18d809a..d200733 100644 --- a/examples/compose/librenms.env +++ b/examples/compose/librenms.env @@ -3,6 +3,7 @@ UPLOAD_MAX_SIZE=16M OPCACHE_MEM_SIZE=128 REAL_IP_FROM=0.0.0.0/32 REAL_IP_HEADER=X-Forwarded-For +LOG_IP_VAR=http_x_forwarded_for LIBRENMS_POLLER_THREADS=16 LIBRENMS_POLLER_INTERVAL=5