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

What can Nginx do?

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

Share

Shulou(Shulou.com)05/31 Report--

This article introduces the relevant knowledge of "what can Nginx do?". In the operation of actual cases, many people will encounter such a dilemma. Then let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

Note: this article focuses on nginx without loading third-party modules.

Nginx directory

First, take a look at the directory after nginx installation (take windows as an example), as shown in the following figure

Generally, you only need to pay attention to the nginx.conf file in the conf folder. If there is a problem with startup, you can go to the logs folder to check the relevant logs. Nginx.exe is the entry of the startup program.

HTTP server

Nginx itself is also a server of static resources. When there are only static resources, Nginx can be used as a server. The figure below is as follows

Start nginx, according to the listening port in the figure above, as follows

Listen 80

Server_name localhost

You can directly access localhost to access html/index.html. The request result is as follows:

In addition, nginx can separate static resources from dynamic resources, as shown in the following figure

Therefore, nginx often acts as a static resource server or separates dynamic and static resources.

Reverse proxy

Reverse proxy is probably the most common thing Nginx does. What is reverse proxy? Why do you need a reverse proxy server?

Reverse proxy (Reverse Proxy) means that the proxy server accepts the connection request on the internet, then forwards the request to the server on the internal network, and returns the result obtained from the server to the client requesting the connection on the internet. At this time, the proxy server behaves as a reverse proxy server.

To put it simply, the real server cannot be directly accessed by the external network, so a proxy server is needed. While the proxy server can be accessed by the external network, it is in the same network environment as the real server. Of course, it may be the same server with different ports. As shown below:

The configuration is as follows:

Load balancing

Load balancing is also a common function of Nginx. Load balancing is to allocate requests to multiple operating units for execution. Generally speaking, a service is usually run by multiple instances, so load balancing is very commonly used.

There are three load balancing strategies commonly used in nginx: RR (polling), ip_hash (each request is assigned according to the hash result of accessing ip), and weight. The configuration is as follows

RR:

Ip_hash:

Weight:

Forward agent

Forward proxy, which means a server between the client and the original server, often in order to get content from the original server, the client needs to send a request to the agent and specify the original server. The proxy server then transfers the request to the original server and returns the obtained content to the client. Often the forward proxy is set when the client cannot access the public network ip or dictates a specific ip address, as shown in the following figure

Note: forward proxy, proxy is the client; reverse proxy, proxy is the server. It's different in nature.

The configuration is as follows:

This is the end of what Nginx can do. Thank you for your reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!

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