title: Can't get real-ip from nginx/varnish to pass on, always shows 127.0.0.1
body: <p>I would like to have the real-IP shows up in the server/magento but it keeps falling back to 127.0.0.1</p>
  
  <p>The server is setup as follow:
  - Varnish listen on port 80
  - Nginx listen on port 8080
  - The SSL traffic are passed onto port 80
  The final website it takes to is a magento 2 site</p>
  
  <p>Nginx is version 1.14.0 with with-http_realip_module</p>
  
  <p>My Nginx server block is as follow:</p>
  
  <pre><code>upstream fastcgi_backend {
    server   unix:/var/run/php/php7.2-fpm-magento.sock;
  }
  
  server {
      listen 8080;
      server_name example.example.com;
  
      set $MAGE_ROOT /opt/magento/public_html;
      set $MAGE_MODE developer; # or production
  
      include snippets/letsencrypt.conf;
      include /opt/magento/public_html/nginx.conf.sample;
      error_log /var/log/nginx/example.example.com-8080-error.log;
      access_log /var/log/nginx/example.example.com-8080access.log;
  }
  
  server {
      listen 443 ssl http2;
      server_name example.example.com;
  
      ssl_certificate /etc/letsencrypt/live/example.example.com/fullchain.pem;
      ssl_certificate_key /etc/letsencrypt/live/example.example.com/privkey.pem;
      ssl_trusted_certificate /etc/letsencrypt/live/example.example.com/chain.pem;
      include snippets/ssl.conf;
      include snippets/letsencrypt.conf;
  
      location / {
          proxy_pass http://localhost:80;
          proxy_set_header Host $http_host;
          proxy_set_header X-Forwarded-Host $http_host;
          proxy_set_header X-Real-IP $remote_addr;
          proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
          proxy_set_header X-Forwarded-Proto https;
          proxy_set_header X-Forwarded-Port 443;
      }
      access_log /var/log/nginx/example.example.com-443access.log;
      error_log /var/log/nginx/example.example.com-443error.log;
  }
  </code></pre>
  
  <p>My Nginx access log (8080access.log) shows 127.0.0.1 for all entries
  the error log (8080-error.log) also shows 127.0.0.1 for client
  The SSL traffic, 443 logs, is showing the actual IP.</p>
  
  <p>Below is my Nginx configuration output:</p>
  
  <p><code>configure arguments: --with-cc-opt='-g -O2 -fdebug-prefix-map=/build/nginx-FIJPpj/nginx-1.14.0=. -fstack-protector-strong -Wformat -Werror=format-security -fPIC -Wdate-time -D_FORTIFY_SOURCE=2' --with-ld-opt='-Wl,-Bsymbolic-functions -Wl,-z,relro -Wl,-z,now -fPIC' --prefix=/usr/share/nginx --conf-path=/etc/nginx/nginx.conf --http-log-path=/var/log/nginx/access.log --error-log-path=/var/log/nginx/error.log --lock-path=/var/lock/nginx.lock --pid-path=/run/nginx.pid --modules-path=/usr/lib/nginx/modules --http-client-body-temp-path=/var/lib/nginx/body --http-fastcgi-temp-path=/var/lib/nginx/fastcgi --http-proxy-temp-path=/var/lib/nginx/proxy --http-scgi-temp-path=/var/lib/nginx/scgi --http-uwsgi-temp-path=/var/lib/nginx/uwsgi --with-debug --with-pcre-jit --with-http_ssl_module --with-http_stub_status_module --with-http_realip_module --with-http_auth_request_module --with-http_v2_module --with-http_dav_module --with-http_slice_module --with-threads --with-http_addition_module --with-http_geoip_module=dynamic --with-http_gunzip_module --with-http_gzip_static_module --with-http_image_filter_module=dynamic --with-http_sub_module --with-http_xslt_module=dynamic --with-stream=dynamic --with-stream_ssl_module --with-mail=dynamic --with-mail_ssl_module</code></p>
  
  <p>I have tried to add the following code to /etc/nginx/nginx.conf</p>
  
  <pre><code>set_real_ip_from   127.0.0.1;
  real_ip_header      X-Forwarded-For;
  </code></pre>
  
  <p>And
      set req.http.X-Forwarded-For = client.ip;
  to /etc/varnish/default.vcl, but since it is a magento specific version of Varnish, I placed it like below:</p>
  
  <pre><code>sub vcl_recv {
  set req.http.X-Forwarded-For = client.ip;
  if (req.method == "PURGE") {
      if (client.ip !~ purge) {
          return (synth(405, "Method not allowed"));
      }
      # To use the X-Pool header for purging varnish during automated deployments, make sure the X-Pool header
      # has been added to the response in your backend server config. This is used, for example, by the
      # capistrano-magento2 gem for purging old content from varnish during it's deploy routine.
      if (!req.http.X-Magento-Tags-Pattern &amp;&amp; !req.http.X-Pool) {
          return (synth(400, "X-Magento-Tags-Pattern or X-Pool header required"));
  </code></pre>
  
  <p>After restarting both services I am still getting the same 127.0.0.1 in the log as well as in Magento 2.</p>
  
  <p>I am puzzled, so any help is appreciated!</p>