Nginx first decides which server{} block in the configuration file to use for processing. Assume the following server{} configuration server { listen 80; server_name aaa; ... } server { listen 80; server_name bbb; ... } Nginx will determine which server to use based on the value in the Host field in the incoming http request header{}. If there is no Host field in the request header, or the value in the Host field does not match the {server_name} in the server{} in the Nginx configuration file, the first server{} is used to process the request. If the value in the Host field in the request header matches the {server_name} in a server{} in the Nginx configuration file, this server{} is used to process the request. You can use the curl tool to easily do experiments. curl can set the request header of the http request, so you can set the Host field arbitrarily, using [-H] to set it. The 10.210.65.73 below is the IP address of the machine where nginx is installed. So using the following command, after sending the http request, nginx will use server{server_name aaa} to process the request. curl.exe -H "Host: aaa" 10.210.65.73 Very important conclusion: server_name corresponds to the value of the Host field in the http request header. With the above theoretical support, it is easy to set up reverse proxy and load balancing: When the Host field in the incoming http request header is aaa, storage.test will handle it. When the Host field in the incoming http request header is bbb, tracker.test will handle it. #Load balancing configuration, the machine with IP 129 has a high configuration, so the number 27 is given to it to let it handle more upstream storage.test { server 10.210.65.129:80 weight=27; server 10.210.65.130:80 weight=1; } #Load balancing configuration upstream tracker.test { server 10.210.65.52:80 weight=7; server 10.210.65.53:80 weight=2; } #File storage server { listen 80; server_name aaa; location / { #The content after http::// is self-defined, corresponding to the upstream name proxy_pass http://storage.test above; } } #File server tracker server { listen 80; server_name bbb; location / { #The content after http::// is self-defined, corresponding to the upstream name proxy_pass http://tracker.test; } } Whose port is the listen in server{} listening on? What is being listened to is: the port of the process (mostly browsers) that sends the http request (if it is an http request, the port is 80), not the port of the nginx server's own process. Nginx decides which server to use to handle the http request based on the value in the Host field of the http request header and the port of the process that sends the http request (mostly the browser). The above is the full content of this article. I hope it will be helpful for everyone’s study. I also hope that everyone will support 123WORDPRESS.COM. You may also be interested in:
|
<<: An example of elegant writing of judgment in JavaScript
>>: Mysql Sql statement exercises (50 questions)
Sometimes the input box is small, and you want to...
Table of contents Overview Build Process Related ...
Table of contents 1. Repeated declaration 1.1 var...
Table of contents Logical Layering Separate busin...
Effect html <div class="sp-container"...
There are many form elements. Here is a brief sum...
SQL statement /* Some methods of eliminating dupl...
Web Services are concerned with application-to-ap...
In HTML pages, we sometimes need to automatically ...
In this article, we’ll explore how async/await is...
1. Storage Engine In the last section, we mention...
This article mainly introduces the simple impleme...
The function I want to achieve is to open a new w...
Data Type: The basic rules that define what data ...
This article example shares the simple implementa...