Locaiton has four types of matching rules, namely, full match (=), prefix normal match (^~), regular expression match (~ or ~*), normal match rule
illustrate
Location is used to quickly locate resources and define different ways to process or resolve URL requests, generally: /, = /, ~, ~*, ^~ 1. Location / Matching# "/" is to search for resources directly in the nginx release directory /usr/local/nginx/html/, such as location.html location / { root html; index index.html index.htm; } Create a location.html file in the release directory with the content: this is location.html. root@backupserver:/usr/local/nginx/html# ls 50x.html index.html root@backupserver:/usr/local/nginx/html# echo "this is location.html" > ./location.html root@backupserver:/usr/local/nginx/html# ls 50x.html index.html location.html root@backupserver:/usr/local/nginx/html# /usr/local/nginx/sbin/nginx -s reload root@backupserver:/usr/local/nginx/html# curl 172.16.0.9/location.html this is location.html root@backupserver:/usr/local/nginx/html# 2. Location = / Match Precise positioning is generally used to match a certain file and has a higher priority than / server { listen 80; server_name localhost; #charset koi8-r; #access_log logs/host.access.log main; location / { autoindex on; root html; index index.html index.htm; } location = /location.html { root /data/; index index.html; } Restart the Nginx service and test: Create a location.html file in the /data directory root@backupserver:/usr/local/nginx/html# ls /data/ www root@backupserver:/usr/local/nginx/html# echo "this is other location.com" > /data/location.html root@backupserver:/usr/local/nginx/html# ls 50x.html index.html location.html root@backupserver:/usr/local/nginx/html# curl 172.16.0.9/location.html this is other location.com root@backupserver:/usr/local/nginx/html# As you can see above, when accessing the server, the server first looks in location = /, even if it is under another location. Exact match has the highest priority. No matter it is above or below the configuration file content, the server will first look for the exact match content. In addition to exact matches, there are ~, ~*, ^~ The above rules are widely used when using nginx, for example, when multiple servers are used to separate static and dynamic websites: location ~ .*\.(html|htm|js|css|txt|png|jpg|jpeg|doc)$ { root html; } This is the end of this article about the common rule priorities of Nginx location. For more relevant content about Nginx location rule priorities, please search for previous articles on 123WORDPRESS.COM or continue to browse the following related articles. I hope you will support 123WORDPRESS.COM in the future! You may also be interested in:
|
<<: The difference between div and span in HTML (commonalities and differences)
>>: MySQL Series 8 MySQL Server Variables
The worst option is to sort the results by time a...
Docker has been very popular in the past two year...
SQLyog connects to mysql error number 1129: mysql...
Today is still a case of Watch app design. I love...
This article mainly introduces the analysis of My...
mysqlslap Common parameter description –auto-gene...
<br />Original: http://www.alistapart.com/ar...
CSS background: background:#00ffee; //Set the back...
Overview This article is a script for automatical...
I summarized the previous notes on installing MyS...
1: Docker private warehouse installation 1. Downl...
Background: I want to install a SAP ECC server an...
Table of contents Preface Implementation ideas Im...
Introduction <br />Not everyone has access t...
1. Download the axios plugin cnpm install axios -...