Nginx proxy module

by Clément Nedelcu | September 2013 |
<p>In this article created by <b>Cl&eacute;ment Nedelcu</b>, the author of <a target="_blank" href="http://www.packtpub.com/nginx-http-server-second-edition/book/dp/nginxhttpserver-abr1/0713?utm_source=dp_nginxhttpserver_abr1_0713&amp;utm_medium=content&amp;utm_campaign=dipali">Nginx HTTP Server - Second Edition</a>,we will discover the proxy module of Nginx.</p>
<p style="margin-left: 40px; margin-right: 40px;" mce_style="margin-left: 40px; margin-right: 40px;" align="center"><i>(For more resources related to this topic, see <a href="#more" mce_href="#more">here</a>.)</i></p> <p>The first step towards establishing the new architecture will be to discover the appropriate module. The default Nginx build comes with the proxy module, which allows forwarding of HTTP requests from the client to a backend server. We will be configuring multiple aspects of the module:</p> <ul> <li>Basic address and port information on the backend server</li> <li>Caching, buffering, and temporary file options</li> <li>Limits, timeout, and error behavior</li> <li>Other miscellaneous options</li> </ul> <p>All these options are available via directives which we will learn to configure throughout this section.</p> <h2>Main directives</h2> <p>The first set of directives will allow you to establish basic configuration such as the location of the backend server, information to be passed, and how it should be passed.</p> <p>Table 1</p> <h2>Caching, buffering, and temporary files</h2> <p>Ideally, as much as possible, you should reduce the amount of requests being forwarded to the backend server. The following directive will help you build a caching system, as well as control buffering options and the way Nginx handles temporary files:</p> <p>Table 2</p> <h2>Limits, timeouts, and errors</h2> <p>The following directives will help you define timeout behavior, as well as various limitations regarding communications with the backend server:</p> <p>Table 3</p> <h2>Other directives</h2> <p>Finally, the last set of directives available in the proxy module is uncategorized and is as follows:</p> <p>Table 4</p> <h2>Variables</h2> <p>The proxy module offers several variables that can be inserted in various locations, for example, in the <i>proxy_set_header</i> directive or in the logging-related directives such as <i>log_format</i>. The available variables are:</p> <ul> <li> <i>$proxy_host</i>: Contains the hostname of the backend server used for the current request.</li> <li> <i>$proxy_port</i>: Contains the port of the backend server used for the current request.</li> <li> <i>$proxy_add_x_forwarded_for</i>: This variable contains the value of the <i>X-Forwarded-For</i> request header, followed by the remote address of the client. Both values are separated by a comma. If the <i>X-Forwarded-For</i> request header is unavailable, the variable only contains the client remote address.</li> <li> <i>$proxy_internal_body_length</i>: Length of the request body (set with the <i>proxy_set_body directive</i> or <i>0</i>).</li> </ul> <h1>Summary</h1> <p>In this article, we learned to discover an appropriate module before establishing a new connection. We configured multiple aspects of the module.</p> <h2>Resources for Article : </h2><p><br></p><hr noshade="noshade" size="1"> <p><b><a class="mceItemAnchor" name="more"><span style="color: rgb(0, 0, 0);" mce_style="color: #000000;">Further resources on this subject:</span></a></b></p> <ul> <li><a href="http://www.packtpub.com/article/introduction-to-nginx" mce_href="http://www.packtpub.com/article/introduction-to-nginx">Introduction to nginx</a> [Article]</li> <li><a href="http://www.packtpub.com/article/nginx-http-server-faqs" mce_href="http://www.packtpub.com/article/nginx-http-server-faqs" target="_blank">Nginx HTTP Server FAQs</a> [Article]</li> <li><a href="http://www.packtpub.com/article/using-nginx-reverse-proxy" mce_href="http://www.packtpub.com/article/using-nginx-reverse-proxy" target="_blank">Using Nginx as a Reverse Proxy</a> [Article]</li> </ul> <hr noshade="noshade" size="1">

About the Author :


Clément Nedelcu

Clément Nedelcu was born in France and studied in UK, French, and Chinese universities. After teaching computer science and programming in several eastern Chinese universities, he worked as a Technology Consultant in France, specializing in web and Microsoft .NET programming as well as Linux server administration. Since 2005, he has also been administering a major network of websites in his spare time. This eventually led him to discover Nginx: it made such a difference that he started his own blog about it. One thing leading to another…

Books From Packt

<hr /> <table style="border-collapse: collapse;" border="0" cellpadding="3" width="588"> <tbody> <tr> <td valign="top" width="68"> <p align="center"><span style="font-family: Verdana; font-size: xx-small;"> <a href="http://www.packtpub.com/mastering-nginx-guide-for-novice-and-advanced-user/book/dp/nginxhttpserver-abr1/0913?utm_source=dp_nginxhttpserver_abr1_0913&amp;utm_medium=content&amp;utm_campaign=dipali"> <img src='//dgdsbygo8mp3h.cloudfront.net/sites/default/files/blank.gif' data-original="http://www.packtpub.com/sites/default/files/7447OS_cov.jpg" border="0" alt="Mastering Nginx" title="Mastering Nginx" width="49" height="61" /></a> <br /> <a href="http://www.packtpub.com/mastering-nginx-guide-for-novice-and-advanced-user/book/dp/nginxhttpserver-abr1/0913?utm_source=dp_nginxhttpserver_abr1_0913&amp;utm_medium=content&amp;utm_campaign=dipali"> Mastering Nginx</a> </span></p> </td> <td valign="top" width="68"> <p align="center"><span style="font-family: Verdana; font-size: xx-small;"> <a href="http://www.packtpub.com/instant-nginx-starter/book/dp/nginxhttpserver-abr1/0913?utm_source=dp_nginxhttpserver_abr1_0913&amp;utm_medium=content&amp;utm_campaign=dipali"> <img src='//dgdsbygo8mp3h.cloudfront.net/sites/default/files/blank.gif' data-original="http://www.packtpub.com/sites/default/files/5125OS_cov.jpg" border="0" alt="Instant Nginx Starter [Instant]" title="Instant Nginx Starter [Instant]" width="49" height="61" /></a> <br /> <a href="http://www.packtpub.com/instant-nginx-starter/book/dp/nginxhttpserver-abr1/0913?utm_source=dp_nginxhttpserver_abr1_0913&amp;utm_medium=content&amp;utm_campaign=dipali"> Instant Nginx Starter [Instant]</a> </span></p> </td> <td valign="top" width="68"> <p align="center"><span style="font-family: Verdana; font-size: xx-small;"> <a href="http://www.packtpub.com/nginx-http-server/book/dp/nginxhttpserver-abr1/0913?utm_source=dp_nginxhttpserver_abr1_0913&amp;utm_medium=content&amp;utm_campaign=dipali"> <img src='//dgdsbygo8mp3h.cloudfront.net/sites/default/files/blank.gif' data-original="http://www.packtpub.com/sites/default/files/0868OS_MockupCover.jpg" border="0" alt="Nginx HTTP Server" title="Nginx HTTP Server" width="49" height="61" /></a> <br /> <a href="http://www.packtpub.com/nginx-http-server/book/dp/nginxhttpserver-abr1/0913?utm_source=dp_nginxhttpserver_abr1_0913&amp;utm_medium=content&amp;utm_campaign=dipali"> Nginx HTTP Server</a> </span></p> </td> <td valign="top" width="68"> <p align="center"><span style="font-family: Verdana; font-size: xx-small;"> <a href="http://www.packtpub.com/nginx-1-web-server-implementation-cookbook/book/dp/nginxhttpserver-abr1/0913?utm_source=dp_nginxhttpserver_abr1_0913&amp;utm_medium=content&amp;utm_campaign=dipali"> <img src='//dgdsbygo8mp3h.cloudfront.net/sites/default/files/blank.gif' data-original="http://www.packtpub.com/sites/default/files/4965OS_Nginx%201%20Web%20Server%20Implementation%20Cookbook.jpg" border="0" alt=" Nginx 1 Web Server Implementation Cookbook" title="Nginx 1 Web Server Implementation Cookbook" width="49" height="61" /></a> <br /> <a href="http://www.packtpub.com/nginx-1-web-server-implementation-cookbook/book/dp/nginxhttpserver-abr1/0913?utm_source=dp_nginxhttpserver_abr1_0913&amp;utm_medium=content&amp;utm_campaign=dipali"> Nginx 1 Web Server Implementation Cookbook</a> </span></p> </td> <td valign="top" width="68"> <p align="center"><span style="font-family: Verdana; font-size: xx-small;"> <a href="http://www.packtpub.com/squid-proxy-server-31-beginners-guide/book/dp/nginxhttpserver-abr1/0913?utm_source=dp_nginxhttpserver_abr1_0913&amp;utm_medium=content&amp;utm_campaign=dipali"> <img src='//dgdsbygo8mp3h.cloudfront.net/sites/default/files/blank.gif' data-original="http://www.packtpub.com/sites/default/files/3906OS_Squid%20Proxy%20Server%203%20Beginners%20Guide_FrontCover.jpg" border="0" alt="Squid Proxy Server 3.1: Beginner's Guide" title="Squid Proxy Server 3.1: Beginner's Guide" width="49" height="61" /></a> <br /> <a href="http://www.packtpub.com/squid-proxy-server-31-beginners-guide/book/dp/nginxhttpserver-abr1/0913?utm_source=dp_nginxhttpserver_abr1_0913&amp;utm_medium=content&amp;utm_campaign=dipali"> Squid Proxy Server 3.1: Beginner's Guide</a> </span></p> </td> <td valign="top" width="68"> <p align="center"><span style="font-family: Verdana; font-size: xx-small;"> <a href="http://www.packtpub.com/ext-js-4-first-look/book/dp/nginxhttpserver-abr1/0913?utm_source=dp_nginxhttpserver_abr1_0913&amp;utm_medium=content&amp;utm_campaign=dipali"> <img src='//dgdsbygo8mp3h.cloudfront.net/sites/default/files/blank.gif' data-original="http://www.packtpub.com/sites/default/files/6662OS_Ext%20JS%204%20First%20Look.jpg" border="0" alt="Ext JS 4 First Look" title="Ext JS 4 First Look" width="49" height="61" /></a> <br /> <a href="http://www.packtpub.com/ext-js-4-first-look/book/dp/nginxhttpserver-abr1/0913?utm_source=dp_nginxhttpserver_abr1_0913&amp;utm_medium=content&amp;utm_campaign=dipali"> Ext JS 4 First Look</a> </span></p> </td> <td valign="top" width="68"> <p align="center"><span style="font-family: Verdana; font-size: xx-small;"> <a href="http://www.packtpub.com/jboss-esb-beginners-guide/book/dp/nginxhttpserver-abr1/0913?utm_source=dp_nginxhttpserver_abr1_0913&amp;utm_medium=content&amp;utm_campaign=dipali"> <img src='//dgdsbygo8mp3h.cloudfront.net/sites/default/files/blank.gif' data-original="http://www.packtpub.com/sites/default/files/6587OS_JBoss%20ESB%20Begineer%27s%20Guide_cov.jpg" border="0" alt="JBoss ESB Beginner&rsquo;s Guide" title="JBoss ESB Beginner&rsquo;s Guide" width="49" height="61" /></a> <br /> <a href="http://www.packtpub.com/jboss-esb-beginners-guide/book/dp/nginxhttpserver-abr1/0913?utm_source=dp_nginxhttpserver_abr1_0913&amp;utm_medium=content&amp;utm_campaign=dipali"> JBoss ESB Beginner&rsquo;s Guide</a> </span></p> </td> <td valign="top" width="68"> <p align="center"><span style="font-family: Verdana; font-size: xx-small;"> <a href="http://www.packtpub.com/openstack-cloud-computing-cookbook/book/dp/nginxhttpserver-abr1/0913?utm_source=dp_nginxhttpserver_abr1_0913&amp;utm_medium=content&amp;utm_campaign=dipali"> <img src='//dgdsbygo8mp3h.cloudfront.net/sites/default/files/blank.gif' data-original="http://www.packtpub.com/sites/default/files/7324OS_OpenStack%20Cloud%20Computing%20cookbook.jpg" border="0" alt="OpenStack Cloud Computing Cookbook" title="OpenStack Cloud Computing Cookbook" width="49" height="61" /></a> <br /> <a href="http://www.packtpub.com/openstack-cloud-computing-cookbook/book/dp/nginxhttpserver-abr1/0913?utm_source=dp_nginxhttpserver_abr1_0913&amp;utm_medium=content&amp;utm_campaign=dipali"> OpenStack Cloud Computing Cookbook</a> </span></p> </td> </tr> </tbody> </table> <hr />
No votes yet

Post new comment

CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.
p
j
1
f
x
i
Enter the code without spaces and pay attention to upper/lower case.
Code Download and Errata
Packt Anytime, Anywhere
Register Books
Print Upgrades
eBook Downloads
Video Support
Contact Us
Awards Voting Nominations Previous Winners
Judges Open Source CMS Hall Of Fame CMS Most Promising Open Source Project Open Source E-Commerce Applications Open Source JavaScript Library Open Source Graphics Software
Resources
Open Source CMS Hall Of Fame CMS Most Promising Open Source Project Open Source E-Commerce Applications Open Source JavaScript Library Open Source Graphics Software