nginx location introduction
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 syntax of ”/uri/”, which can be a string or a regular expression. But if you want to use a regular expression, you must specify a prefix.
nginx location syntax
Basic syntax: location [=|
~|
~*|
^~] /uri/{ … }
= Strict match. If this query matches, the search will stop and the request will be processed immediately. ~ for case-sensitive matching (available regular expressions) ~* for case-insensitive matching (can be used with regular expressions) !~ and !~* are case-insensitive and case-insensitive respectively ^~ This prefix is used for a regular string, then tells nginx not to test the regular expression if the path matches.
Location syntax: location [=|
~|
~*|
^~] /uri/{ … } Note: 1, ~ for case-sensitive matching 2, ~ * for case-insensitive matching 3, !~ and !~* are case-insensitive and case-insensitive Mismatch
Example 1:
location /{ }
Matches any query because all requests start with /. But the regular expression rules will be matched first with the query.
Example 2:
Code is as follows location =/{}
Just match /
Example 3:
Code is as follows location ~* .(gif|
Jpg|
Jpeg)$ { rewrite .(gif|
Jpg) $ /logo.png; }
Note: Case-insensitive matching of any file ending with gif, jpg, jpeg
nginx location application example
Code is as follows
location = /{ # Only match /query. }location /{ # Matches any query because all requests have been /started. But regular expression rules and long block rules will be matched first with the query. }location ^~ /images/{ # Matches any queries that start with /images/and stops searching. Any regular expression will not be tested. }location ~* .(gif|
Jpg|
Jpeg)$ { # Matches any request that ends with gif, jpg, or jpeg. }location ~* .(gif|
Jpg|
Swf)$ { valid_referers none blocked start.igrow.cn sta.igrow.cn; if ($invalid_referer) { #防盗链 rewrite ^/http://$host/logo.png; } } location ~* .(js|
Css|
Jpg|
Jpeg|
Gif|
Png|
Swf)$ { if (-f $request_filename) { #Set expiration time according to file type expires 1h; break; } } location ~* .(txt|
Doc)${ #Disallow access to a directory root /data/www/wwwroot/linuxtone/test; deny all; }
++ 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
-E Each packet intercepted shows the link layer header: source MAC address > d
There is no doubt that MDaemon developed by Alt-n of the United States is an excellent mail server s
which is again a problem with the client Exchange server. Exchange 2003 and DC are the same server.
I. Summary This article summarizes how to enable Gzip compression for websites hosted with IIS, the
The IIS log analysis tool (point grid IIS log analyzer) uses graphic tutorial
Apache ThreadsPerChild and MaxRequestsPerChild configuration analysis
Linux to build FTP server with vsftpd
Advantages of blade servers large inventory of
The network operator's five misunderstandings in the log analysis
IIS has a "requested resource in use" solution
Seven newbie skills Deadly server security maintenance
Talking about the threats encountered by the paid website
Windows 2000 server IIS open the parent path step
Can I use a desktop computer as a server?
Enterprises choose the right server Five attentions should not forget
How to query the computer problem report of Win10 system
Use Alipay and import digital certificates under Windows 7
Win10 does not insert the U disk but shows the safe removal of the hardware icon. The
Win7 practical tips to delete the search history of the search bar
Win7 system windows help and support can not be closed how to solve?
Win10 uses the command to uninstall the system's own application method
Windows 7 open taskbar settings window