I'm having a setup for Magento 2 with Nginx + Varnish + SSL in ubuntu server 18.04. Now with my setup, I only get all logs in Nginx and inside Magento admin coming from same localhost IP which Varnish listens.

I want to change that.

What the best way to do it?
Using Nginx and


Or reconfigure Varnish with a GeoIP module I found here: Varnish GeoIP

For option one will this add in my Nginx conf file work?

server {
    listen 8082;
    real_ip_header     X-Forwarded-For;
    <Other Server Options>

Do I need to change something in Magento



  • how is your request going? because nginx on port :80 hardly the right place. – MagenX Jun 15 '19 at 19:09
  • @MagenX sorry for this. I corrected in my question the conf file. Request goes to varnish first as my setup is configured with nginx as proxy pass – G. G. Jun 15 '19 at 20:06

to help you debug this, you can add this php file for example, headers.php:

foreach($_SERVER as $key_name => $key_value) {
print $key_name . "  =  <font style='color: rgb(0,0,255);'>" . $key_value . "</font><br/>";

where you can see all the headers.

make sure you proxy pass correct header:

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

add remote IP variations and check headers with file above.

  • Although this was not the solution for my problem it helped me to solve it – G. G. Jun 18 '19 at 14:56
  • impossible to write something specific, we dont see your configuration – MagenX Jun 18 '19 at 17:14
  • you are absolutely right. Question wasn't for getting the configuration. Question was if it is better to use ngx_http_realip_module or Varnish geoip – G. G. Jun 18 '19 at 17:17
  • 1
    great it actually working :) – MagenX Jun 18 '19 at 20:50

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.