title: Get real Visitors IP in Apache behind Nginx reverse proxy dont work
body: <p>After 5 hours trying to solve the problem and read any tutorial i have found, i ask here for help.</p>
  
  <p>I have an <code>Nginx Reverse Proxy</code> Server that points to my <code>Apache</code> Web Server, but on <code>Apache</code> i got just the <code>IP address</code> from <code>Nginx reverse proxy</code> server not visitors ip.</p>
  
  <p><strong>My nginx proxy file:</strong> <code>/etc/nginx/sites-available/proxy.conf</code></p>
  
  <pre><code>proxy_pass http://MYIPADDRESS;
  proxy_next_upstream error timeout invalid_header http_500 http_502 http_503 http_504;
  proxy_redirect off;
  proxy_buffering off;
  proxy_set_header        Host            $host;
  proxy_set_header        X-Forwarded-For $proxy_add_x_forwarded_for;
  proxy_set_header        X-Real-IP       $remote_addr;
  </code></pre>
  
  <p>On Apache i have added to <code>/etc/apache2/apache2.conf</code> file:</p>
  
  <pre><code>RemoteIPHeader X-Forwarded-For
  </code></pre>
  
  <p>and replaced</p>
  
  <pre><code>LogFormat "%a %l %u %t \"%r\" %&gt;s %O \"%{Referer}i\" \"%{User-Agent}i\"" combined
  </code></pre>
  
  <p>with</p>
  
  <pre><code>LogFormat "%h %l %u %t \"%r\" %&gt;s %b \"%{Referer}i\" \"%{User-Agent}i\" %{X-Forwarded-For}i" combined
  </code></pre>
  
  <p><code>a2enmod remoteip</code> also enabled</p>
  
  <p>Also in Nginx <code>/var/log/nginx/access.log</code> file i got always just <code>localhost</code> IP like:</p>
  
  <pre><code>127.0.0.1 - - [27/Jan/2020:23:53:07 +0800] "GET...
  </code></pre>
  
  <p>Also have tried to add to <code>/etc/nginx/nginx.conf</code>:</p>
  
  <pre><code>set_real_ip_from 127.0.0.1;
  real_ip_header X-Forwarded-For
  </code></pre>
  
  <p>If i run on my Webserver now an PHP Script in Browser:</p>
  
  <pre><code>&lt;?php
  
  echo 'User IP - '.$_SERVER['REMOTE_ADDR'];
  
  ?&gt;
  </code></pre>
  
  <p>I just got the Reverse Proxy Servers IP and its the same for whole server. </p>
  
  <p>Both Servers OS are Debian 9, any one an idea? Many Thanks!</p>