Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Nginx Project (1): reverse proxy and configuration of Nginx

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/02 Report--

Abstract: starting from the concept of Nginx, this paper introduces one of the characteristics of Nginx, reverse proxy, from three aspects: concept, advantage and configuration code.

Article Source: creditworthy Institute of Technology & Technology sharing of CITIC payment and settlement team Phase I-Zhou Heng, Senior Technical Manager of Citic payment and settlement Octagonal data team, "details of Nginx"

Shared by: Zhou Heng, senior technical manager of Yixin payment and settlement octagonal data team

The original text was first posted on the official account of the payment and settlement technical team: wild pointer.

I. interpretation of the concept of Nginx

The best way to understand new things is to start with concepts. As the first article in a series of "Nginx Topics", this article starts with the name of Nginx to decompose this mysterious engine.

Nginx, the abbreviation of engine X and pronounced 'engine X', was developed by Russian god Igor Sessoyev in 2004 and provides high-performance and easy-to-use HTTP reverse proxy function. In the later stage, reverse proxy support for TCP was added.

Originally, Nginx was born to solve the C10K problem in the early years. What is C10K? C stands for Client customers and 10K for 10000, that is, a server maintains 10, 000 links at the same time. This was a very thorny problem at that time.

Search for Nginx through Google and you will get the following explanation:

Nginx is a web server with an asynchronous framework and can also be used as a reverse proxy, load balancer, and HTTP cache.

From this sentence, we can get the following key points:

Asynchronous framework reverse proxy load balancing HTTP cache

This feature article will interpret the power of Nginx from these keywords. This paper first introduces the reverse proxy of the Nginx feature and its configuration implementation. ​

Reverse proxy 2.1 what is a reverse proxy

Agents are very common in daily life, housing agents are agents, terminal retail agents are agents, and elected representatives are agents. These agents can help the demand side reduce the complexity of a lot of work and improve efficiency and experience.

I think readers are very clear about what the proxy service looks like in the network. Let's briefly review here: suppose we want to watch bilibili's video on the Internet in the company, while the standard company, for the sake of security and office efficiency, set up a network policy and do not allow access to video websites. Smart programmers can not be defeated by these things, just buy a cloud service and build an agent service. By setting the browser on the proxy, you can easily access the video website. This is a common agent.

So now the question is: "agent" everyone knows, why is it emphasized that it is a reverse agent? Is there a forward agent? The answer is yes.

Forward agent is a common agent, which is called "forward agent" from the point of view of the requesting side, that is, the client. At this point, the user actively chooses to use the agent.

Reverse proxy: look at the picture before you explain.

The initiative is reversed, originally the client chooses the agent, now the agent selects the server node. Due to the reversal of control, such agents are called "reverse agents".

2.2 advantages of reverse proxy

1) protect the security of services

The IP; that hides the service node places the service node behind the firewall to avoid directly attacking the ji business node server.

2) Service nodes focus more on business and improve performance at the same time

Due to the existence of reverse proxy, the reverse proxy server can be allowed to implement business-independent functions such as https and gzip compression, and provide dynamic and static separation to send static files to static servers or local file systems to prevent business nodes from processing these non-business-related requests. A caching mechanism is provided to increase the cache at the reverse proxy server layer to reduce the number of requests of the business server, which will not change in a short period of time. Since the control lies in the proxy service, requests can be dynamically allocated according to the performance of the service node to achieve the best performance of the service node.

It is precisely because Ngxin introduces the feature of reverse proxy, which makes both request and response go through Nginx, which brings a lot of possibilities to Nginx. For example, load balancing, HTTP cache and so on.

III. Configuration of reverse proxy

The configuration of reverse proxies in Nginx is fairly simple.

3.1 configure a single-node reverse proxy # simple reverse-proxyserver {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;}}

The rule defined here is to request port 80 of Nginx with the big.server.com domain name, which will proxy the request to 127.0.0.1 8080.

3.2 configure a set of service nodes for reverse proxies.

1) configure a set of reverse proxies and name them.

Upstream big_server_com {server 192.168.0.1 virtual 8000; server 192.168.0.1 virtual 8001;}

Upstream is defined here, and this upstream can be understood as upload stream. It is called upload because getting data from the server is called downloading, and sending data to the server is called upload. Here, the data request is sent to the service node, so it is called upload.

Name this set of service nodes big_server_com, which includes two nodes, namely: 192.168.0.1 virtual 8000 and 192.168.0.1 virtual 8001.

2) configuration rules: enable satisfied requests to reverse proxy to this set of service nodes.

Server {listen 80; server_name big.server.com; access_log logs/big.server.access.log main; location / {proxy_pass http://big_server_com;}}

The rule defined here is to request port 80 of Nginx with the domain name of big.server.com. All requests with the suffix / url are forwarded to the previously defined service node group named big_server_com.

IV. Summary

Starting from the concept of Nginx, this paper introduces one of the characteristics of Nginx, reverse proxy, from three aspects: concept, advantage and configuration code. Follow-up articles will continue to introduce three other features of Nginx: load balancing, HTTP caching, and asynchronous framework.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report