K
K
Kirill Petrov2014-09-09 06:10:25
Nginx
Kirill Petrov, 2014-09-09 06:10:25

How to pass user IP to Nginx proxy?

There is a proxy on Nginx, config

server {
    listen 80 default; 
    server_name _; 
    server_tokens off;
location / {
    proxy_pass http://$http_host$request_uri;
    proxy_set_header Host $http_host;
    resolver 8.8.8.8;
  proxy_set_header Accept-Encoding "";
  proxy_hide_header Vary;
  gzip on;
  gzip_vary on;
  gzip_proxied any;
  gzip_http_version 1.0;
}
}

But when I go through it to the same site 2ip.ru, I see the IP of the server where the proxy is, and not my own. Please help. Thank you.

Answer the question

In order to leave comments, you need to log in

3 answer(s)
A
Anton Solomonov, 2014-09-09
@Wendor

You will not be able to replace the proxy address with your own in any case.
You can send the real IP with an additional header to the server:

proxy_set_header        X-Real-IP       $remote_addr;
proxy_set_header        X-Forwarded-For $proxy_add_x_forwarded_for;

C
Cool Admin, 2014-09-09
@ifaustrue

In proxy \ NAT mode, this cannot be done. Routing only, i.e. not nginx.

V
Vlad Zhivotnev, 2014-09-10
@inkvizitor68sl

You need to pass the client address in the X-Real-IP header.
"By default" foreign web servers only accept this header from the localhost.
So you cannot organize such a proxy on other sites.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question