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
1. Introduction to MariaDB and MySQL 1. Introduct...
Application scenario 1: Domain name-based redirec...
1. Install JDK Check the computer's operating...
Sometimes when requesting certain interfaces, you...
This is a website I imitated when I was self-stud...
illustrate DML (Data Manipulation Language) refer...
When releasing a project, you will often encounte...
Table of contents 1. watch monitoring properties ...
IE has had problems for a long time. When everyone...
HTML5 adds more semantic tags, such as header, fo...
Table of contents 1. Prototype mode Example 1 Exa...
Today, CSS preprocessors are the standard for web...
It is recommended that you do not set the width, h...
Table of contents mysql master-slave replication ...
This article example shares the specific code of ...