Book Image

Mastering Nginx

By : Dimitri Aivaliotis
Book Image

Mastering Nginx

By: Dimitri Aivaliotis

Overview of this book

<p>NGINX is a high-performance HTTP server and mail proxy designed to use very few system resources. With the many tutorials and example configurations floating around the Web, it is difficult to know how to properly configure NGINX to meet your expectations.<br /><br />"Mastering Nginx" will serve to clarify the murky waters of NGINX configuration, helping you learn how to tune NGINX for various situations, what some of the more obscure configuration directives do, and how to design a decent configuration to match your needs.<br /><br />Beginning with an overview of compiling NGINX and describing its basic configuration file format, this guide next takes you on a tour of NGINX's modules.</p> <p>From the unique mail module to the upstream module, this book explores the various possibilities of using NGINX as a reverse proxy. The multiple HTTP modules are explained, and the book rounds off the tour with a discussion of troubleshooting.</p> <p>"Mastering Nginx" will explain all aspects of configuring NGINX to help solve your hosting problems.</p>
Table of Contents (19 chapters)
Mastering NGINX
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Persisting Solaris Network Tunings
Index

Determining the client's real IP address


When using a proxy server, the clients don't have a direct connection to the upstream servers. The upstream servers, therefore, aren't able to get information directly from those clients. Any information, such as the client's IP address, would need to be passed via headers. NGINX provides this with the proxy_set_header directive:

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

The client's IP address will then be available in both the X-Real-IP and X-Forwarded-For headers. The second form takes a client request header into account. If present, the IP address of the request will be added to the X-Forwarded-For header from the client, separated by a comma. Depending on your upstream server configuration, you will need one or the other of these. Configuring Apache, for example, to use the X-Forwarded-For header for the client's IP address in its logs is done using the %{<header-name>}i formatting...