TheRobotLearns Platform · ProxySQL: from first install to production
Preserve Real Client IPs with PROXY Protocol
Learning objectives
- Explain how PROXY protocol preserves original client and proxy socket information.
- Identify ProxySQL support for PROXY protocol v1 over TCP4 and TCP6.
- Configure mysql-proxy_protocol_networks with trusted CIDRs for allowed proxy headers.
- Apply trusted-subnet guidance to reject wildcard proxy header sources.
- Inspect preserved PROXY data by enabling extended processlist and querying stats_mysql_processlist.
Where the real client IP goes
You run ProxySQL behind a load balancer. The connections reach ProxySQL from the balancer, so logging can show the balancer address instead of the client address. ProxySQL can preserve the original client connection information when traffic passes through proxies, load balancers, or TCP intermediaries.
That preservation supports accurate logging and security checks. It also supports auditing and compliance. The PROXY protocol carries connection data such as the client IP address and source port, plus the proxy IP address and proxy port.
ProxySQL can use that data for logging, security checks, and routing decisions. The client information available for logging includes the original client IP and original client port. The proxy information includes the proxy IP, the proxy port, and PROXY v1 details.
A web application behind a load balancer can keep accurate client IP logging for security analysis. A multi-tenant platform can use regional load balancer networks for per-tenant policies and compliance.
Takeaway: PROXY protocol keeps the client and proxy connection details available when ProxySQL sits behind an intermediary.
What ProxySQL accepts
You point a load balancer at ProxySQL and must choose a PROXY protocol version. ProxySQL supports version 1, with TCP4 for IPv4 and TCP6 for IPv6. A v1 header follows a fixed field order.
It begins with PROXY. It then names the address family. The next fields are the original client address and the proxy address. They are followed by the client port and the proxy port. Protocol termination is \r\n.
The header example PROXY TCP4 255.255.255.255 192.168.1.1 12345 3306 gives client address 255.255.255.255 and proxy address 192.168.1.1. It gives client port 12345 and proxy port 3306. The TCP6 example uses IPv6-form addresses.
AWS Network Load Balancer supports PROXY protocol, but ProxySQL only supports v1. You may need a TCP proxy such as HAProxy in front of ProxySQL, or configure the NLB target group appropriately. HAProxy can send PROXY protocol v1 with send-proxy. A malformed header is rejected. ProxySQL can use the preserved details for routing decisions.
Takeaway: Support is PROXY protocol v1 for TCP4 and TCP6.
Trusting only your proxies
You decide which proxies may send PROXY headers. The variable mysql-proxy_protocol_networks controls the allowed networks, so a client outside those networks cannot supply spoofed header data.
The syntax is two statements: assign the list, then load variables to runtime. An empty string disables PROXY protocol and is the default. An asterisk accepts PROXY headers from any network. Specific lists use comma-separated CIDR notation.
For example, '192.168.1.0/24,10.0.0.0/8' accepts those IPv4 ranges, and '2001:db8::/32,fe80::/10' accepts those IPv6 ranges. You can also mix IPv4 and IPv6, such as '192.168.1.0/24,2001:db8::/32'. A web application behind a load balancer can use '10.0.0.0/8'. A multi-tenant platform can use several load balancer networks.
This command sets a trusted IPv4 list and loads it into RUNTIME; SHOW VARIABLES LIKE 'proxy_protocol_networks'; returns that current value.
SET mysql-proxy_protocol_networks = '10.0.1.0/24,10.0.2.0/24';
LOAD MYSQL VARIABLES TO RUNTIME;Use the smallest possible subnets for security. List only trusted proxy or load balancer IP ranges. Do not leave '*' in production.
Takeaway: Set mysql-proxy_protocol_networks to trusted CIDRs, then load the variables to RUNTIME.
When headers do not appear
You enable trusted subnets, yet a connection with a PROXY header is rejected. Check that mysql-proxy_protocol_networks includes the proxy address. Use SHOW VARIABLES LIKE 'proxy_protocol_networks'; to see the current setting.
If the balancer sends malformed headers, those headers are rejected. If connections timeout after PROXY protocol is enabled, check connectivity between the proxy and ProxySQL. Use netcat to test with and without a PROXY header. The current network setting and stats_mysql_connection_pool give debug data.
To inspect preserved information, enable extended processlist information first. When mysql-show_processlist_extended is enabled, PROXY protocol data is available in stats_mysql_processlist. The query selects ThreadID, user, and cli_host. It returns extended_info where that column is not null.
Backend database version does not affect PROXY protocol support, because ProxySQL handles it at the connection layer. PROXY information appears in connection logs and JSON exports. It also appears in statistics and audit trails.
SHOW VARIABLES LIKE 'proxy_protocol_networks';
SET mysql-show_processlist_extended = 1;
LOAD MYSQL VARIABLES TO RUNTIME;
SELECT ThreadID, user, cli_host, extended_info
FROM stats_mysql_processlist
WHERE extended_info IS NOT NULL;Takeaway: Diagnose rejected headers with SHOW VARIABLES, and inspect preserved data through extended processlist queries.
Enable trusted networks, then inspect extended processlist
SET mysql-proxy_protocol_networks = '10.0.1.0/24,10.0.2.0/24';
LOAD MYSQL VARIABLES TO RUNTIME;
SET mysql-show_processlist_extended = 1;
LOAD MYSQL VARIABLES TO RUNTIME;
SHOW VARIABLES LIKE 'proxy_protocol_networks';
SELECT ThreadID, user, cli_host, extended_info
FROM stats_mysql_processlist
WHERE extended_info IS NOT NULL;SET mysql-proxy_protocol_networks = '10.0.1.0/24,10.0.2.0/24'; assigns a comma-separated CIDR list that names the trusted proxy subnets. LOAD MYSQL VARIABLES TO RUNTIME; loads that variable into RUNTIME. SET mysql-show_processlist_extended = 1; enables extended processlist information. LOAD MYSQL VARIABLES TO RUNTIME; loads that variable into RUNTIME. SHOW VARIABLES LIKE 'proxy_protocol_networks'; returns the current network list. SELECT ThreadID, user, cli_host, extended_info FROM stats_mysql_processlist WHERE extended_info IS NOT NULL; returns preserved PROXY data when present.
Try it: config_layer_sim
Connect to the ProxySQL admin interface. Run this command set:
SET mysql-proxy_protocol_networks = '10.0.1.0/24';
LOAD MYSQL VARIABLES TO RUNTIME;
SHOW VARIABLES LIKE 'proxy_protocol_networks';The SHOW VARIABLES result returns the current network list. Then run:
SET mysql-show_processlist_extended = 1;
LOAD MYSQL VARIABLES TO RUNTIME;
SELECT ThreadID, user, cli_host, extended_info FROM stats_mysql_processlist WHERE extended_info IS NOT NULL;The SELECT returns preserved PROXY data when extended processlist information is enabled. Set mysql-proxy_protocol_networks to '*', load it to RUNTIME, and confirm that headers from any network are accepted.
Sources
- PROXY Protocol Support
- PROXY Protocol Support
- PROXY Protocol Support
- PROXY Protocol Support
- PROXY Protocol Support
- PROXY Protocol Support
- PROXY Protocol Support
- PROXY Protocol Support
- PROXY Protocol Support
- PROXY Protocol Support
- PROXY Protocol Support
- PROXY Protocol Support
- PROXY Protocol Support
- PROXY Protocol Support
- PROXY Protocol Support
- PROXY Protocol Support
- PROXY Protocol Support
- PROXY Protocol Support
- PROXY Protocol Support
- PROXY Protocol Support
- PROXY Protocol Support
- PROXY Protocol Support
- PROXY Protocol Support
- PROXY Protocol Support
- PROXY Protocol Support
- PROXY Protocol Support
- PROXY Protocol Support
- PROXY Protocol Support
- PROXY Protocol Support
- PROXY Protocol Support
- PROXY Protocol Support
- PROXY Protocol Support
- PROXY Protocol Support
- PROXY Protocol Support
- PROXY Protocol Support
- PROXY Protocol Support
- PROXY Protocol Support
- PROXY Protocol Support
- PROXY Protocol Support
- PROXY Protocol Support
- PROXY Protocol Support
- PROXY Protocol Support
- PROXY Protocol Support
- PROXY Protocol Support
- PROXY Protocol Support
- PROXY Protocol Support
- PROXY Protocol Support
- PROXY Protocol Support
- PROXY Protocol Support
- PROXY Protocol Support
Do more with an account
- Graded quizzes is available on your account.
- Saving your progress is available on your account.
- Hands-on labs is available on your account.
- AI tutoring is available on your account.