Skip to main content
ubuntuask.com

Back to all posts

How to Get A Real Client IP Directly From NGINX?

Published on
5 min read
How to Get A Real Client IP Directly From NGINX? image

Best Tools to Buy for Accurate IP Tracking in NGINX in March 2026

1 REOLINK PTZ Security Camera System 4K, IP PoE 360 Camera with Dual-Lens, Auto 6X Hybrid Zoomed Tracking, 355 Pan & 90 Tilt, Outdoor Surveillance, AI Detection, TrackMix PoE

REOLINK PTZ Security Camera System 4K, IP PoE 360 Camera with Dual-Lens, Auto 6X Hybrid Zoomed Tracking, 355 Pan & 90 Tilt, Outdoor Surveillance, AI Detection, TrackMix PoE

  • DUAL LENSES PROVIDE DETAILED CLOSE-UPS AND PANORAMIC VIEWS IN ONE.
  • SMART DETECTION TRACKS MOVEMENTS AND ALLOWS QUICK VIDEO PLAYBACK.
  • INSTANT ALERTS WITH SPOTLIGHTS AND NOTIFICATIONS ENSURE YOUR SAFETY.
BUY & SAVE
$189.99
REOLINK PTZ Security Camera System 4K, IP PoE 360 Camera with Dual-Lens, Auto 6X Hybrid Zoomed Tracking, 355 Pan & 90 Tilt, Outdoor Surveillance, AI Detection, TrackMix PoE
2 TONGVEO 4K NDI PTZ Camera AI Auto-Tracking 20X Optical Zoom HDMI IP Live Streaming SDI USB3.0 PoE LAN Supports for Church Worship Event Video Conference YouTube OBS vMix Zoom Teams and More

TONGVEO 4K NDI PTZ Camera AI Auto-Tracking 20X Optical Zoom HDMI IP Live Streaming SDI USB3.0 PoE LAN Supports for Church Worship Event Video Conference YouTube OBS vMix Zoom Teams and More

  • STUNNING 4K/30FPS CLARITY FOR PROFESSIONAL-GRADE LIVE STREAMING.

  • OFFICIAL NDI INTEGRATION FOR SEAMLESS STREAMING ON ALL MAJOR PLATFORMS.

  • AI AUTO-TRACKING ENSURES DYNAMIC CONTENT STAYS PERFECTLY FRAMED.

BUY & SAVE
$459.00
TONGVEO 4K NDI PTZ Camera AI Auto-Tracking 20X Optical Zoom HDMI IP Live Streaming SDI USB3.0 PoE LAN Supports for Church Worship Event Video Conference YouTube OBS vMix Zoom Teams and More
3 BOAVISION 2K Security Camera Outdoor, Wireless WiFi IP Camera Home Security System 360° View,Motion Detection, auto Tracking,Two Way Talk, pan Tile Full Color Night Vision 5G/2.4G WiFi

BOAVISION 2K Security Camera Outdoor, Wireless WiFi IP Camera Home Security System 360° View,Motion Detection, auto Tracking,Two Way Talk, pan Tile Full Color Night Vision 5G/2.4G WiFi

  • AUTO-TRACKING CAMERA CAPTURES EVERY MOVING MOMENT SEAMLESSLY!
  • BUILT-IN FLOODLIGHT & ALARM DETER INTRUDERS INSTANTLY!
  • CRYSTAL-CLEAR 1080P VIDEO WITH 350° PAN FOR COMPLETE COVERAGE!
BUY & SAVE
$39.89
BOAVISION 2K Security Camera Outdoor, Wireless WiFi IP Camera Home Security System 360° View,Motion Detection, auto Tracking,Two Way Talk, pan Tile Full Color Night Vision 5G/2.4G WiFi
4 Anpviz UltraHD 4K 8MP PTZ POE IP Camera Outdoor with 5X Optical Zoom, 1/2.8" Sensor Dome Security IP Camera, Two-Way Audio, Human Vehicle Detection, 512GB SD Slot, 100ft IR Night Vision (U Series)

Anpviz UltraHD 4K 8MP PTZ POE IP Camera Outdoor with 5X Optical Zoom, 1/2.8" Sensor Dome Security IP Camera, Two-Way Audio, Human Vehicle Detection, 512GB SD Slot, 100ft IR Night Vision (U Series)

  • 4K ULTRA HD & IR NIGHT VISION: CAPTURE STUNNING 20FPS VIDEO, 100FT RANGE.
  • 5X OPTICAL ZOOM & WIDE PAN/TILT: FLEXIBLE ANGLES WITHOUT LOSING QUALITY.
  • SMART MOTION ALERTS & TWO-WAY AUDIO: STAY CONNECTED, RECEIVE INSTANT NOTIFICATIONS.
BUY & SAVE
$124.99
Anpviz UltraHD 4K 8MP PTZ POE IP Camera Outdoor with 5X Optical Zoom, 1/2.8" Sensor Dome Security IP Camera, Two-Way Audio, Human Vehicle Detection, 512GB SD Slot, 100ft IR Night Vision (U Series)
5 REOLINK 4K 8MP 180° Dual-Lens PoE IP Camera, IK10 Vandal-Proof, Person/Vehicle/Animal Detection, Spotlight Color Night Vision, 2 Way Talk, IP67 Weatherproof, No PT Supported, Duo 2V PoE

REOLINK 4K 8MP 180° Dual-Lens PoE IP Camera, IK10 Vandal-Proof, Person/Vehicle/Animal Detection, Spotlight Color Night Vision, 2 Way Talk, IP67 Weatherproof, No PT Supported, Duo 2V PoE

  • CAPTURE STUNNING 8MP IMAGES & 180° VIEWS WITH DUAL-LENS DESIGN.
  • GET REAL-TIME ALERTS WITH AI DETECTION FOR PEOPLE, VEHICLES, AND PETS.
  • IK10 VANDAL-PROOF AND CUSTOMIZABLE NIGHT VISION FOR ULTIMATE SECURITY.
BUY & SAVE
$159.99
REOLINK 4K 8MP 180° Dual-Lens PoE IP Camera, IK10 Vandal-Proof, Person/Vehicle/Animal Detection, Spotlight Color Night Vision, 2 Way Talk, IP67 Weatherproof, No PT Supported, Duo 2V PoE
6 Tapo 2K Indoor/Outdoor Dual Lens Pan/Tilt Wired Security Camera - 125° Wide-Angle View + 6mm Zoom, Motion Track, Person/Vehicle Detection, Subscription-Free Local Storage or Optional Cloud, C246D

Tapo 2K Indoor/Outdoor Dual Lens Pan/Tilt Wired Security Camera - 125° Wide-Angle View + 6mm Zoom, Motion Track, Person/Vehicle Detection, Subscription-Free Local Storage or Optional Cloud, C246D

  • DUAL 2K LENS FOR WIDE COVERAGE & PRECISION ZOOM!
  • AI-POWERED DETECTION FOR TAILORED ALERTS-NO FEES!
  • ADAPTABLE NIGHT VISION MODES FOR ALL ENVIRONMENTS!
BUY & SAVE
$59.99 $69.99
Save 14%
Tapo 2K Indoor/Outdoor Dual Lens Pan/Tilt Wired Security Camera - 125° Wide-Angle View + 6mm Zoom, Motion Track, Person/Vehicle Detection, Subscription-Free Local Storage or Optional Cloud, C246D
7 Anpviz 6MP PoE PTZ Camera Outdoor, 5X Optical Zoom 2.7~13.5mm Lens, Pan Tilt Zoom IP Security Camera with Human Vehicle Detection, Spotlight&Sound Alarm, SD Card Slot, IP66, NDAA Compliant (U Series)

Anpviz 6MP PoE PTZ Camera Outdoor, 5X Optical Zoom 2.7~13.5mm Lens, Pan Tilt Zoom IP Security Camera with Human Vehicle Detection, Spotlight&Sound Alarm, SD Card Slot, IP66, NDAA Compliant (U Series)

  • CAPTURE VIVID 6MP HD VIDEO AT 25FPS WITH SMOOTH PERFORMANCE.
  • PAN/TILT/ZOOM WITH 280° VIEW & IP66 RATING FOR ALL WEATHER CONDITIONS.
  • SMART ALERTS FOR HUMAN/VEHICLE DETECTION FOR ENHANCED SECURITY.
BUY & SAVE
$99.98
Anpviz 6MP PoE PTZ Camera Outdoor, 5X Optical Zoom 2.7~13.5mm Lens, Pan Tilt Zoom IP Security Camera with Human Vehicle Detection, Spotlight&Sound Alarm, SD Card Slot, IP66, NDAA Compliant (U Series)
8 Kasa 1080p Indoor Pan/Tilt Wired Security Camera - Works as a Baby & Pet Monitor, Motion Detection & Tracking, 2-Way Audio, Night Vision, Subscription-Free Local Storage or Optional Cloud, EC71

Kasa 1080p Indoor Pan/Tilt Wired Security Camera - Works as a Baby & Pet Monitor, Motion Detection & Tracking, 2-Way Audio, Night Vision, Subscription-Free Local Storage or Optional Cloud, EC71

  • 360° PAN/TILT VIEW: MONITOR EVERY CORNER WITH FULL ROOM COVERAGE.
  • REAL-TIME ALERTS: INSTANT NOTIFICATIONS FOR CRUCIAL DETECTIONS AND TRACKING.
  • 2-WAY AUDIO: COMFORT YOUR PETS ANYTIME, ANYWHERE THROUGH THE APP.
BUY & SAVE
$21.98 $27.99
Save 21%
Kasa 1080p Indoor Pan/Tilt Wired Security Camera - Works as a Baby & Pet Monitor, Motion Detection & Tracking, 2-Way Audio, Night Vision, Subscription-Free Local Storage or Optional Cloud, EC71
9 JideTech 200X Hybrid Zoom 4K 8MP Outdoor PTZ IP PoE Security Camera, Auto Tracking Dome Surveillance Camera, Human/Vehicle Detection, 492ft IR Night Vision, Two-Way Talk, IP66, for RTMP,Blue Iris

JideTech 200X Hybrid Zoom 4K 8MP Outdoor PTZ IP PoE Security Camera, Auto Tracking Dome Surveillance Camera, Human/Vehicle Detection, 492ft IR Night Vision, Two-Way Talk, IP66, for RTMP,Blue Iris

  • STUNNING 200X HYBRID ZOOM & 4K HD FOR UNMATCHED VIDEO CLARITY!

  • REAL-TIME AUTO TRACKING & SMART DETECTION FOR ENHANCED SECURITY!

  • IP66 WATERPROOF DESIGN ENSURES RELIABILITY IN ALL WEATHER CONDITIONS!

BUY & SAVE
$299.99
JideTech 200X Hybrid Zoom 4K 8MP Outdoor PTZ IP PoE Security Camera, Auto Tracking Dome Surveillance Camera, Human/Vehicle Detection, 492ft IR Night Vision, Two-Way Talk, IP66, for RTMP,Blue Iris
+
ONE MORE?

To get the real client IP directly from NGINX, you can use the ngx_http_realip_module module. This module allows NGINX to replace the client IP address in the request headers with the address sent in the X-Forwarded-For or X-Real-IP headers.

Follow these steps to configure NGINX to obtain the real client IP:

  1. Open the NGINX configuration file typically located at /etc/nginx/nginx.conf or /etc/nginx/conf.d/default.conf.
  2. Inside the http block, add the following line to load the ngx_http_realip_module module: load_module /usr/lib/nginx/modules/ngx_http_realip_module.so;
  3. Within the http block, add the following lines to set the real_ip_header variable to the appropriate header value: set_real_ip_from 10.0.0.0/8; real_ip_header X-Forwarded-For; Replace 10.0.0.0/8 with the appropriate CIDR notation for your trusted proxy IP address or subnet range.
  4. Below the previous lines, add the following line to restore the original client IP address: real_ip_recursive on;
  5. Save the configuration file and exit the text editor.
  6. Test the NGINX configuration for syntax errors: nginx -t
  7. If the test is successful, reload NGINX to apply the changes: systemctl reload nginx

Once NGINX is configured, it will use the value from the X-Forwarded-For or X-Real-IP header as the client IP address instead of the default value obtained by NGINX. This allows you to accurately trace the client IP in your NGINX logs or use it for any other purposes within your NGINX configuration.

How to configure NGINX to obtain the client IP address?

To configure NGINX to obtain the client IP address, you can follow these steps:

  1. Open your NGINX configuration file. Depending on the operating system and NGINX installation method, the file could be located at /etc/nginx/nginx.conf or /etc/nginx/conf.d/default.conf or /etc/nginx/sites-available/default.
  2. Inside the main http block, add or modify the http or server block to include the following line: set_real_ip_from 0.0.0.0/0; # Set the IP range from which NGINX should trust proxy requests real_ip_header X-Forwarded-For; # The header that contains the real IP address Alternatively, if you're behind a load balancer or reverse proxy, you can use the X-Real-IP header instead of X-Forwarded-For: real_ip_header X-Real-IP;
  3. Save the configuration file and exit the editor.
  4. Test the configuration syntax for any errors by running the command: nginx -t
  5. If there are no syntax errors, reload the NGINX configuration to apply the changes by running the command: nginx -s reload

After configuring NGINX to obtain the client IP address, you can access it in your application or web server logs using the REMOTE_ADDR environment variable.

How to check if NGINX is running on a server?

You can use the following command to check if NGINX is running on a server:

sudo systemctl status nginx

This command will display the status of the NGINX service. If NGINX is running, you will see output similar to:

● nginx.service - The NGINX HTTP Server Loaded: loaded (/lib/systemd/system/nginx.service; enabled; vendor preset: enabled) Active: active (running) since Tue 2021-04-13 10:00:00 PDT; 1h ago Docs: http://nginx.org/en/docs/ Main PID: 12345 (nginx) Tasks: 2 (limit: 4915) Memory: 4.0M CPU: 1.000s CGroup: /system.slice/nginx.service ├─12345 nginx: master process /usr/sbin/nginx -g daemon on; master_process on; └─12346 nginx: worker process

If NGINX is not running, you will see output indicating that the service is inactive or not found.

Note: The exact command may vary depending on the operating system and how NGINX is installed on the server.

What is an NGINX rewrite rule?

An NGINX rewrite rule is a configuration setting that allows rewriting or modifying URL paths or query strings sent by clients before processing the request. It enables the server to redirect or serve content from different locations based on certain conditions defined by regular expressions. NGINX rewrite rules are commonly used for URL redirection, modifying query strings, masking internal file paths, and implementing SEO-friendly URLs.

How to block specific IP addresses using NGINX?

To block specific IP addresses using NGINX, you can follow these steps:

  1. Open the NGINX configuration file. This file is typically located in the /etc/nginx/ directory and is named nginx.conf.
  2. Inside the http block, add a new server block to define the configurations for blocking the IP addresses: http { ... server { ... } }
  3. Inside the server block, add a new location block to specify the path or URL where you want to block the IP addresses: http { ... server { ... location /block/path { ... } } }
  4. Inside the location block, use the deny directive to specify the IP addresses you want to block: http { ... server { ... location /block/path { deny 192.168.1.1; deny 10.0.0.0/24; ... } } } You can use either the IP address or IP range format (CIDR notation) to specify the IP addresses you want to block.
  5. Save the configuration file and exit the text editor.
  6. Test the NGINX configuration to ensure it is valid: $ nginx -t
  7. If the configuration test is successful, reload or restart NGINX for the changes to take effect: $ systemctl reload nginx or $ service nginx restart

With these steps, NGINX will deny access to the specified IP addresses for the specified path or URL. If any requests come from these IP addresses, NGINX will return a forbidden (403) error.