(For more resources related to this topic, see here.)
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:
- Basic address and port information on the backend server
- Caching, buffering, and temporary file options
- Limits, timeout, and error behavior
- Other miscellaneous options
All these options are available via directives which we will learn to configure throughout this section.
Main directives
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.
Table 1
Caching, buffering, and temporary files
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:
Table 2
Limits, timeouts, and errors
The following directives will help you define timeout behavior, as well as various limitations regarding communications with the backend server:
Table 3
Other directives
Finally, the last set of directives available in the proxy module is uncategorized and is as follows:
Table 4
Variables
The proxy module offers several variables that can be inserted in various locations, for example, in the proxy_set_header directive or in the logging-related directives such as log_format. The available variables are:
- $proxy_host: Contains the hostname of the backend server used for the current request.
- $proxy_port: Contains the port of the backend server used for the current request.
- $proxy_add_x_forwarded_for: This variable contains the value of the X-Forwarded-For request header, followed by the remote address of the client. Both values are separated by a comma. If the X-Forwarded-For request header is unavailable, the variable only contains the client remote address.
- $proxy_internal_body_length: Length of the request body (set with the proxy_set_body directive or 0).
Summary
In this article, we learned to discover an appropriate module before establishing a new connection. We configured multiple aspects of the module.
Resources for Article :
Further resources on this subject:
- Introduction to nginx [Article]
- Nginx HTTP Server FAQs [Article]
- Using Nginx as a Reverse Proxy [Article]