Nginx topic (1): Nginx reverse proxy and the configuration

Abstract: In this paper, the concept of Nginx, respectively, from the reverse proxy concept, advantages, configuration code 3 introduces one of the characteristics of Nginx reverse proxy.

Source: Institute of Technology & Yixin Yixin payment and settlement technology team to share the first phase - Zhou Heng "Nginx minutiae" letter should pay settlement data Supply team, senior technical manager

Shared by: letter should be paid Zhou Heng settlement data Supply team, senior technical manager

Original starting in payment and settlement technology team recognized number: dangling pointers

A, Nginx interpretation of the concept

To understand new things, the best way is to start from the concept paper as "Nginx topic" first article in the series, starting with the name of Nginx begins to break down this mysterious engine.

Nginx, is an abbreviation engine X, the pronunciation is the 'engine x', Russia in 2004 by the god Igor Saisuoyefu developed to provide high performance and easy to use HTTP reverse proxy functionality. The latter also joined the TCP reverse proxy support.

Nginx is the first to solve the C10K problem early and students. C10K What is it? Client C on behalf of clients, 10K behalf of 10000, that is, a server while maintaining the 10,000 links. This is a very difficult issue at the time.

Google search Nginx will get the following explanation:

Nginx web server is asynchronous frame can also be used as a reverse proxy, load balancers and HTTP caching.

From this statement, we can get a few key below:

  • Asynchronous frame
  • Reverse Proxy
  • Load Balancing
  • HTTP caching

This feature articles respectively from a few key words to interpret the power of the Nginx. This article first describes the characteristics of the reverse proxy Nginx configuration and implementation.

Second, reverse proxy

2.1 What is a reverse proxy

Acting is very common in life, real estate agents are agents, terminal retail is the agent, the agent is the elected representatives. These agents can help reduce the complexity of the demand side a lot of work to enhance the efficiency and experience.

The network proxy service is what, I think our readers are very clear, here again briefly recall: Suppose we want to see the video in the Internet company B station, and standardized corporate office for security and efficiency set network policy does not allow access video sites, clever programmers can not be defeated by these things, as long as the purchase of a cloud service, set up a proxy service, the proxy settings on your browser, you can easily access video sites. This is a common agent.

So now the question is: "agent" we know everything, why the emphasis here is reverse proxy it? Is there a forward proxy? The answer is yes.

Forward proxy is all the common agent to request end is the client's point of view is positive, the requesting user through a proxy, referred to as "forward proxy." In this case the user is actively choose to use a proxy.

Reverse Proxy: look at the map to explain.

The initiative was reversed, turned out to be a client to select a proxy, the proxy now select the server node. Since the inversion control over, such agents are known as "reverse proxy."

2.2 reverse proxy advantages

1) protection services security

  • Hide IP service node;
  • After the service node behind the firewall, to avoid a direct attack on the service node server.

2) focus more on the business service node, while improving performance

  • Because there is a reverse proxy, the reverse proxy server can make to achieve such https, gzip compression and other business-related functions;
  • Providing separate static and dynamic, static or static server files sent to the local file system to avoid the service node processes the requested service independent;
  • Provide caching mechanism, some of the short time will not change the dynamic content in this layer increases the reverse proxy server cache, a request to reduce the amount of traffic the server;
  • Since the control over the service agent side, it can be dynamically allocated according to the performance request the serving node, serving node to achieve the best performance.

It is because of the introduction of reverse proxy Ngxin features make requests and responses go through Nginx, Nginx therefore to bring a lot of possibility. Such as load balancing, HTTP caching.

Third, the reverse proxy configuration

Nginx configuration on the reverse proxy is quite simple.

3.1 Reverse proxy configuration of a single node

# simple reverse-proxy
server { 
    listen       80;
    server_name  big.server.com;
    access_log   logs/big.server.access.log  main;

    # pass requests for dynamic content to rails/turbogears/zope, et al
    location / {
      proxy_pass      http://127.0.0.1:8080;
    }
  }

 

Here are 80 rules defined port big.server.com Nginx domain name request, the request will be proxied to the 127.0.0.1:8080.

3.2 Configuring a reverse proxy group of service nodes.

1) and configuring a set of reverse proxy name.

upstream big_server_com {
    server 192.168.0.1:8000;
    server 192.168.0.1:8001;
}

 

This defines the upstream, the upstream flow can be understood as upload, upload was called due to: obtain data downloaded from the server to call, send data uploaded to the server is called, here is the data request to the service node, so called uploading.

This set of services to the node named big_server_com, including two nodes, namely: 192.168.0.1: 8000 and 192.168.0.1:8001.

2) configuration rules: Let's meet can request a reverse proxy service to this set of nodes.

server { 
    listen          80;
    server_name     big.server.com;
    access_log      logs/big.server.access.log main;

    location / {
      proxy_pass      http://big_server_com;
    }
  }

 

Here is big.server.com domain-defined rules to Nginx port 80 request, the request url is / suffix for all requests will be forwarded to the previously defined name for big_server_com service node group.

IV Summary

Starting from the concept of Nginx, respectively, from the reverse proxy concept, advantages, configuration code 3 introduces one of the characteristics of Nginx reverse proxy. Subsequent articles will continue to introduce Nginx other three features: load balancing, HTTP caching, asynchronous framework, so stay tuned.

Guess you like

Origin www.cnblogs.com/yixinjishu/p/11804225.html