문제

I'm trying to get HAProxy to pass the user's IP address by using:

option forwardfor 

In my haproxy.cnf

But for some reason my express returns no IP address. This is the code I'm using in Node.js:

    var usrIP = "0";
    if( req.connection.remoteAddress !== null || req.connection.remoteAddress !== "null" || req.connection.remoteAddress.length > 1 ) {
        usrIP = req.connection.remoteAddress;
    }

Any ideas what could be wrong?

도움이 되었습니까?

해결책

You'll get client IP in headers.

"forwardfor" option which will add an "X-Forwarded-For" header with the original client's IP address. You must also use "httpclose" to ensure that you will rewrite every requests and not only the first one of each session :

    option httpclose
    option forwardfor

Line 122 http://haproxy.1wt.eu/download/1.2/doc/architecture.txt

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top