N
N
nsnoob2022-01-27 12:49:27
linux
nsnoob, 2022-01-27 12:49:27

How to set up header proxying without changes in nginx?

Good for all!
How to configure NGINX so that the headers of sent requests remain unchanged?

Thank you in advance

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander Karabanov, 2022-01-27
@karabanov

I add a test location to the Nginx config:

location /test/ {
      proxy_set_header  Host test.com;
      proxy_set_header  X-Forwarded-For $remote_addr;
      proxy_set_header  X-Real-IP $remote_addr;
      proxy_http_version 1.1;
      proxy_pass http://192.168.254.1:3434/;
    }

I force NetCat to listen on port 3434 nc -lvp 3434
I make a request for a test location and substitute a custom header:
curl -H "X-Test: test" https://example.com/test/
I look at the NetCat output and see:
Listening on [0.0.0.0] (family 0, port 3434)
Connection from 172.17.0.2 43098 received!
GET / HTTP/1.1
Host: test.com
X-Forwarded-For: 192.168.254.254
X-Real-IP: 192.168.254.254
Connection: close
user-agent: curl/7.68.0
accept: */*
x-test: test

Received both the custom header and the headers added by the proxy server.
Conclusion, either there is an error in the application to which the request is proxied, so it is not able to receive the headers, or the headers above in the Nginx config are specially removed, or the headers are really missing in the request.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question