1. Introduction The location instruction is the core configuration of the http module. It receives requests sent by users according to pre-defined URL matching rules. According to the matching results, it forwards the requests to the background server, directly rejects illegal requests and returns 403, 404, 500 error processing, etc. 2. Location command syntax location [=|~|~*|^~|@] /uri/ { … } or location @name { … } 3. URI matching pattern The location directive is divided into two matching modes: 4. Location URI matching rules When nginx receives a request, it intercepts the URI part of the request and searches for URI matching patterns defined in all location instructions. In the server module, you can define multiple location instructions to match different URL requests and URI matching patterns for different location configurations. The overall matching principle is: match the common string pattern first, then match the regular pattern. Only recognize the URI part, for example, the request is: /test/abc/user.do?name=xxxx When a request comes in, the process of Nginx matching this request is as follows: 1> First check whether there is an exact match starting with =, such as: location = /test/abc/user.do { … } 2> Search for a normal match again, based on the principle of the largest prefix. If there are the following two locations, the latter one will be matched 3> After matching a common pattern, the search does not end, but the current matching result is temporarily stored and the search for the regular matching pattern continues 4> After all regular matching patterns find the first matching item in location, this item will be used as the final matching result. Therefore, the matching rules of regular matching items are affected by the order of definition, but ordinary matching patterns are not. 5> If no regular match is found, the cached result in step 3 is used as the final match result 5. Differences between exact matching and fuzzy matching 6. Regular and irregular matching 1> location ~ /test/.+.jsp$ { … }: Regular matching, supporting standard regular expression syntax. ... http { ... server { listen 80; server_name localhost; location / { root html; index index.html index.htm; # deny all; reject the request and return 403 # allow all; allow request} location /abc { deny all; } location ~ /.+\.jsp$ { proxy_pass http://location:9090; } # Match all jsp files in the /test path location ~ /test/.+\.jsp$ { proxy_pass http://localhost:8080; } # Define various error pages error_page 404 /404.html error_page 500 502 503 504 /50x.html; location = /50x.html { root html; } # @Similar to variable definition# error_page 403 http://blog.csdn.net; #This definition is not allowed, and it is required to use @ to define temporary variables to implement error_page 403 @page403; location @page403 { proxy_pass http://blog.csdn.net; } } } 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:
|
<<: MySQL 5.7.20 Green Edition Installation Detailed Graphic Tutorial
>>: Vue implements the right slide-out layer animation
Preface What is data type conversion? The default...
WIN10 64-bit install the latest MySQL8.0.18 downl...
Table of contents Preface first step: Step 2: Mod...
1. Download 1. Click the latest download from the...
<br />We have always emphasized semantics in...
1. Introduction The difference between row locks ...
1. at is configured to write "This is a at t...
This article shares the installation tutorial of ...
For security reasons, Alibaba Cloud Server ECS co...
In some cases, the data in data needs to be reuse...
MySQL partitioning is helpful for managing very l...
Table of contents Exporting Docker containers Imp...
Set the table's style="table-layout:fixed...
Today, I logged into the server and prepared to m...
Table of contents 1:mysql execution process 1.1: ...