diff --git a/README.md b/README.md index b1a4a1b..a4fa3c6 100644 --- a/README.md +++ b/README.md @@ -48,6 +48,8 @@ It's a fork of [CrazyMax's LibreNMS Docker image repository](https://github.com/ * `MEMORY_LIMIT` : PHP memory limit (default `256M`) * `UPLOAD_MAX_SIZE` : Upload max size (default `16M`) * `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`) #### (Distributed) Poller diff --git a/assets/tpls/etc/nginx/nginx.conf b/assets/tpls/etc/nginx/nginx.conf index d3f22d8..ea57a09 100644 --- a/assets/tpls/etc/nginx/nginx.conf +++ b/assets/tpls/etc/nginx/nginx.conf @@ -30,8 +30,8 @@ http { tcp_nodelay on; ## Handling of IPs in proxied and load balancing situations - set_real_ip_from 0.0.0.0/32; - real_ip_header X-Forwarded-For; + set_real_ip_from @REAL_IP_FROM@; + real_ip_header @REAL_IP_HEADER@; ## Hide the Nginx version number server_tokens off; diff --git a/entrypoint.sh b/entrypoint.sh index 1176949..6e22e98 100644 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -11,6 +11,8 @@ PGID=${PGID:-1000} MEMORY_LIMIT=${MEMORY_LIMIT:-256M} 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"} MEMCACHED_PORT=${MEMCACHED_PORT:-11211} RRDCACHED_PORT=${RRDCACHED_PORT:-42217} @@ -93,7 +95,9 @@ sed -e "s/@OPCACHE_MEM_SIZE@/$OPCACHE_MEM_SIZE/g" \ # Nginx echo "Setting Nginx configuration..." -sed -e "s/@UPLOAD_MAX_SIZE@/$UPLOAD_MAX_SIZE/g" \ +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" \ /tpls/etc/nginx/nginx.conf > /etc/nginx/nginx.conf # SNMP diff --git a/examples/compose/librenms.env b/examples/compose/librenms.env index 7f06b5f..18d809a 100644 --- a/examples/compose/librenms.env +++ b/examples/compose/librenms.env @@ -1,6 +1,8 @@ MEMORY_LIMIT=256M UPLOAD_MAX_SIZE=16M OPCACHE_MEM_SIZE=128 +REAL_IP_FROM=0.0.0.0/32 +REAL_IP_HEADER=X-Forwarded-For LIBRENMS_POLLER_THREADS=16 LIBRENMS_POLLER_INTERVAL=5