0

I am using nginx with upstream for running the webserver and a TURN server on the same port:

stream {
    upstream web {
        server 127.0.0.1:4444;
    }
    upstream turn {
        server 127.0.0.1:5349;
    }
    # since 1.13.10
    map $ssl_preread_alpn_protocols $upstream {
        ~\bh2\b         web;
        ~\bhttp/1\.     web;
        default         turn;
    }
}

server {
    listen 4444 ssl http2 http2 http2;
    listen [::]:4444 ssl http2 http2 http2;
    server_name my.domain;
    # (...)
}

But using this configuration, I only see 127.0.0.1 in the access log. I tried to set X-Forwarded-For in the upstream section, but it is no legal directive there.

What is the best way to log the requests with the real client ip?

2
  • 1
    You could use PROXY protocol nginx.org/en/docs/stream/…
    – Alexey Ten
    May 12 '20 at 9:01
  • @AlexeyTen For some reason I cannot add proxy_protocol to the server section on port 4444. To the main server section on 443 I can add it, but then it is still missing for the upstream server.
    – allo
    May 13 '20 at 16:16
0

You're saying you tried this:

proxy_set_header X-Forwarded-For $remote_addr;

If yes, have you tried this?

proxy_set_header X-Real-IP $remote_addr;
2
  • There is no proxy_set_header directive in streams
    – Alexey Ten
    May 12 '20 at 8:47
  • I cannot set any headers in this part of the configuration.
    – allo
    May 12 '20 at 21:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.