pires / go-proxyproto

A Go library implementation of the PROXY protocol, versions 1 and 2.
Apache License 2.0
478 stars 107 forks source link

Nginx proxy_protocol doesn't work. #94

Closed LaikeeDu closed 1 year ago

LaikeeDu commented 1 year ago

Hi, I've used Nginx as a load balance, and use example/server or example/http as backend. But I can't get real IP from nginx even if I have used the configuration of Nginx like proxy_protocol on

stream {

upstream my_servers{
#least_conn;
server 1.2.3.4:22;
#proxy_protocol      on;
}
server {
listen [::]:223 ipv6only=off;
listen [::]:223 ipv6only=off udp;
proxy_pass my_servers;
proxy_protocol      on;

}
}

The error was: proxyproto: invalid address or it just give me the IP of Nginx. Because I didn't find any thing relative to the problem, so I open the issue asking you for help. I will be appreciate if you can look deep into the problem.

pires commented 1 year ago

I'm sorry but I'm not able to help with this for the time being. I've labeled the issue hoping someone will take a stab at it.

himgoods commented 1 year ago

When the machine has an IPv6 address, nginx may change the original address of Proxy Protocol to IPv4-Mapped IPv6 Address, which is actually displayed as: ::ffff:123.123.123.123 All IPv4 addresses will be prefixed with "::ffff:", and go-proxyproto cannot recognize such addresses, so there will be an error of proxyproto: invalid address.

pires commented 1 year ago

@himgoods in such case is traffic signaled as IPv6, eg TCPv6?

drakkan commented 1 year ago

@himgoods in such case is traffic signaled as IPv6, eg TCPv6?

yes, it si signaled as IPv6. I used this configuration to test my patch

stream {
    server {
        listen              [::]:2222 ipv6only=off;
        #listen              2222;

        proxy_pass          127.0.0.1:2022;
        proxy_protocol      on;
    }
}
pires commented 1 year ago

Thank you, @drakkan.