Go2Linux | Linux Operating System

A site dedicated to: Linux Operating System

Nginx behind varnish or squid Real IP module

Date: 2011-04-17 00:00:00 -0400

Introduction

I’ve been trying to see if I may find some improvement using varnish in front of Nginx to serve static content, well I’ve not finished the test yet, and will be publishing my results here later.

But, in case you decide to run Nginx in front of a proxy, you will find that all lines in access.log file, will have the IP of the proxy, and not the client IP itself.

To solve that, you need to compile Nginx with Real IP module

Using Real IP module with NGINX

The Real IP module in Nginx will do somehow the same job of libapache2-mod-rpaf if Apache were behind Nginx or other reverse proxy.

OK, so you need to compile Nginx with support for Real IP module, to do that proceed, like in this post: Nginx with gzip-static support, but in this case use this option --with-http_realip_module, instead or together with --with-http_gzip_static_module.

After that, you need to configure /etc/nginx/conf/nginx.conf file, and between http {…} tags, add this

                set_real_ip_from 127.0.0.1;
                real_ip_header X-Forwarded-For;

This is valid if Varnish is running in the same computer as Nginx, if not, instead of 127.0.0.1, use the varnish computer’s IP.

If you liked this article please share it.

powered by TinyLetter

If you want to contact me in any other way, please use the contact page.