Home  >  Article  >  Operation and Maintenance  >  How to implement reverse proxy in nginx

How to implement reverse proxy in nginx

(*-*)浩
(*-*)浩Original
2019-06-06 09:15:1010920browse

I recently planned to study the nginx source code and saw online introductions that nginx can be used as a reverse proxy server to complete load balancing. So I collected some information about reverse proxy servers and compiled them.

How to implement reverse proxy in nginx

The reverse proxy method refers to using a proxy server to accept connection requests on the Internet, and then forwarding the requests to the server on the internal network; The results obtained on the server are returned to the client requesting a connection on the Internet. At this time, the proxy server appears as a server to the outside world.

Usual proxy servers are only used to proxy internal network connection requests to the Internet. The client must specify a proxy server and send http requests that are intended to be sent directly to the Web server to the proxy server. When a proxy server can proxy a host on the external network to access the internal network, this proxy service method is called a reverse proxy service.

There are usually two models for implementing a reverse proxy server. It can be used as a stand-in for the content server or as a load balancer for the content server cluster.

As a stand-in for the content server                                                                                                                                Proxy servers act as stand-ins for content servers. When external clients try to access the content server, they are sent to the proxy server. The actual content resides on the content server, which is securely protected inside the firewall. Proxy servers sit outside the firewall and appear to clients as content servers.

When a client makes a request to the site, the request goes to the proxy server. The proxy server then sends the client's request to the content server through a specific path in the firewall. The content server then sends the results back to the proxy server through this channel. The proxy server sends the retrieved information to the client as if the proxy server were the actual content server. If the content server returns an error message, the proxy server intercepts the message and changes any URLs listed in the header before sending the message to the client. This prevents external clients from obtaining the redirect URL for the internal content server.

In this way, the proxy server provides another barrier between the secure database and possible malicious attacks. Even if a lucky attack succeeds, the perpetrator is, at best, limited to accessing the information involved in a single transaction, compared with having access to the entire database. Unauthorized users cannot access the real content server because the firewall path only allows access to the proxy server.

Load balancer as a content server

Multiple proxy servers can be used within an organization to balance the network load among web servers. In this model, you can take advantage of the caching features of the proxy server to create a pool of servers for load balancing. At this point, the proxy server can be on either side of the firewall. If your web server receives a large number of requests every day, you can use a proxy server to share the load on the web server and improve network access efficiency.

The proxy server acts as an intermediary for requests sent from the client to the real server. The proxy server caches the requested document. If there is more than one proxy server, DNS can use "round robin" to select its IP address, routing requests randomly. The client uses the same URL each time, but the route the request takes may go through a different proxy server each time.

You can use multiple proxy servers to handle requests to a high-volume content server. The advantage of this is that the content server can handle a higher load and be more efficient than if it works alone. During initial startup, the proxy server first retrieves documents from the content server, after which the number of requests to the content server drops significantly.

For more Nginx related technical articles, please visit the

Nginx usage tutorial

column to learn!

The above is the detailed content of How to implement reverse proxy in nginx. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn