Home > Article > Backend Development > nginx location configuration instructions
The Location directive in Nginx is an important directive in NginxHttpCoreModule. The Location directive is used to configure the matching URI. The URI is the "/uri/" in the syntax, which can be a string or a regular expression. But if you want to use regular expressions, you must specify a prefix.
nginx location syntax
Basic syntax: location [=|~|~*|^~] /uri/ { … }
= strict match. If this query matches, the search is stopped and the request is processed immediately.
~ is case-sensitive matching (regular expressions are available)
~* is case-insensitive matching (regular expressions are available)
!~ and !~* are case-sensitive mismatching and case-insensitive mismatching respectively
^~ If used with a regular string, this tells nginx not to test the regular expression if the path matches.
Location syntax syntax: location [=|~|~*|^~] /uri/ { … }
Note:
1, ~ are case-sensitive matching
2, ~* are case-insensitive matching
3, !~ and !~* are case-sensitive mismatch and case-insensitive mismatch respectively.
Example 1:
location / { }
matches any query because all requests start with /. But regular expression rules will be prioritized for query matching.
Example 2:
The code is as follows | Copy code |
location =/ {} |
Only matches /
Example 3:
Copy code | |
location ~* .(gif|jpg|jpeg)$ { rewrite .(gif|jpg)$ /logo.png; } |
Note: Matches anything starting with gif, jpg, The file ending in jpeg
nginx location application example
The code is as follows | Copy the code |
location = / { |
++ Some available global variables
$args
$content_length
$content_type
$document_root
$document_uri
$host
$http_user_agent
$http_cookie
$limit_rate
$request_body_file
$request_ method
$remote_addr
$ remote_port
$remote_user
$request_filename
$request_uri
$query_string
$scheme
$server_protocol
$server_addr
$server_name
$server_port
$uri
The above introduces the nginx location configuration instructions, including the relevant content. I hope it will be helpful to friends who are interested in PHP tutorials.