The given configuration sets up an NGINX server to route incoming requests to one of the backend InfluxDB servers specified in the upstream
block. Here's a detailed breakdown of how this works:
Steps to Route Data Using This Configuration:
-
Define the Backend Servers:
- The
upstream influxdb
block lists three backend InfluxDB servers:172.16.35.186:8086
172.16.35.187:8086
172.16.35.188:8086
- NGINX will distribute the incoming requests among these servers based on the default load-balancing strategy (
round-robin
).
- The
-
Listen on Port 8086:
- The
server
block configures NGINX to listen for incoming requests on port8086
at the IP address192.168.2.43
.
- The
-
Forward Requests to Backend:
- The
proxy_pass http://influxdb;
directive forwards all requests to theinfluxdb
upstream block, which distributes them to the configured backend servers.
- The
-
Set Headers for Proxied Requests:
- The following
proxy_set_header
directives set appropriate headers:Host $host
: Passes the originalHost
header from the client.X-Real-IP $remote_addr
: Adds the client's actual IP address.X-Forwarded-For $proxy_add_x_forwarded_for
: Chains the client IP for tracing purposes.X-Forwarded-Proto $scheme
: Indicates whether the original request was made over HTTP or HTTPS.
- The following
What Happens When Data is Routed:
- Client Request: When a client sends a request to
192.168.2.43:8086
, NGINX intercepts it. - Load Balancing: NGINX forwards the request to one of the three InfluxDB servers in the
upstream influxdb
block using the round-robin load-balancing method. - Backend Response: The chosen InfluxDB server processes the request and sends the response back to NGINX.
- Client Response: NGINX then relays the response back to the client.
Verifying Configuration:
-
Test Configuration: Run the following command to ensure the NGINX configuration syntax is correct:
nginx -t
-
Restart NGINX: If the configuration is valid, reload or restart NGINX:
nginx -s reload
-
Check Logs: Check the NGINX logs (
error_log
oraccess_log
) for any errors or routing issues.
Enhancements (Optional):
-
Health Checks: Add health checks for backend servers to ensure traffic isn't sent to unavailable servers:
nginx
upstream influxdb { server 172.16.35.186:8086 max_fails=3 fail_timeout=30s; server 172.16.35.187:8086 max_fails=3 fail_timeout=30s; server 172.16.35.188:8086 max_fails=3 fail_timeout=30s; }
-
Sticky Sessions: If you need requests from the same client to go to the same server, enable sticky sessions:
nginx
upstream influxdb { ip_hash; server 172.16.35.186:8086; server 172.16.35.187:8086; server 172.16.35.188:8086; }
This setup ensures smooth routing of requests to your InfluxDB instances while leveraging NGINX for load balancing and failover.