Simple nginx reverse proxy application

Source: Internet
Author: User
Tags nginx reverse proxy

650) This. width = 650; "style =" border-bottom: 0px; border-left: 0px; border-top: 0px; border-right: 0px "Title =" clip_image002 "border =" 0 "alt =" clip_image002 "src =" http://img1.51cto.com/attachment/201409/23/8914310_1411444865ubDb.gif "" 244 "Height =" 132 "/>

The client does not access the real backend server, but the reverse proxy server. When the client sends a request, the proxy reverse proxy first looks for its own cache to see if any requested resource is available and then returns it directly to the client. If not, it goes to the backend server to retrieve the resource and then returns it to the client, helping the server process the request. nginx works in reverse proxy. When a client request arrives, it is not retrieved from the backend until the request is fully accepted, however, in response to a client request, resources are retrieved from the backend server and the client is returned at the same time. Resources are not obtained after the request is fully received. Therefore, the request is asynchronous. in this way, the pressure on the upstream server can be released.

Nginx uses the proxy module to implement reverse proxy. As a web reverse proxy server, nginx is responsible for receiving customer requests and dispatching user requests to the upstream Server Based on Uri, client parameters, or other processing logic ). The most important command for nginx to implement the reverse proxy function is proxy_pass, which can proxy a URI defined by location to a specified upstream server (group. In the following example, the/uri of location is replaced with the/newuri on the upstream server.

 

Location/uri {

Proxy_pass http://www.centod.com: 8080/newuri;

}

If the URI of location is defined by mode matching, its URI will be passed directly to the game server, rather than another URI for conversion. For example,/forum in the following example will be represented as http://www.centod.com/forum.

Location ~ ^/Forum {

Proxy_pass http://www.centod.com;

}

The second exception is that if URL redirection is used in loation, nginx will use the redirected URI to process the request without considering the URI defined on the upstream server. In the example shown below, the URI sent to the upstream server is/index. php? Page = <match> instead of/index.

Location /{

Rewrite/(. *) $/index. php? Page = $1 break;

Proxy_pass http: // localhost: 8080/index;

}

Proxy Module Instructions

There are many available configuration commands for the proxy module. They are used to define many attributes when the proxy module is working, such as the connection timeout duration and the HTTP protocol version used for proxy. The following is a simple description of commonly used commands.

Proxy_connect_timeout: Maximum waiting time before nginx sends a request to the upstream server;

Proxy_cookie_domain: modifies the domain attribute set by upstream server through the set-Cookie header to a specified value. The value can be a string, a regular expression pattern, or a referenced variable;

Proxy_cookie_path: modifies the path attribute set by upstream server through the set-Cookie header to a specified value. The value can be a string, regular expression mode, or a referenced variable;

Proxy_hide_header: Set the header to be hidden in the message sent to the client;

Proxy_pass: Specifies the URL path from the request proxy to upstream server;

Proxy_set_header: rewrite the header of the message sent to the upsream server;

Proxy_redirect: overwrite the location and refresh the header of the packet received from upstream server;

Proxy_send_timeout: maximum interval between write operations sent to upstream server two times before the connection is disconnected;

Proxy_read_timeout: maximum interval between two read operations received from the upstream server before the connection is disconnected

Simple nginx reverse proxy application

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.