2019.9.20 Nginx Location and separation of static and dynamic case

A, Nginx regular and location match
. 1, Nginx location rule matching
^ ~: identifier matches with a character behind
=: precise match
~: case-insensitive matching
~ *: not sensitive match
! -: negated on a case-sensitive match
! ~ *: For case-insensitive match negated
/: General match
2, regular expressions
*: Repeat the preceding character zero or more times
? : Repeat the previous character 0 or 1
+: Repeat the previous character one or more times
: match any character other than a newline.
(A | B): a matching or B
^: to begin ...
$ : ending ...
{n}: n times repeating the previous character
{n,}: repeat the previous n characters or more times
{n, m}: repeat the previous character nm Ci
*? : Repeat the preceding character zero or more times, but as few repeats
+? : Repeat the preceding character one or more times, but less duplication wherever possible
? ? : Repeat the previous character 0 or 1, but less repeated as
{n, m}? : Repeat the previous character nm times, but as little as possible repetition
{n}? : Repeat the previous character n times or more, but less repeat as
3, regular expressions supplement

\ W: not match any letters, numbers, underscores, Chinese characters (special characters)

\ S: character not match any whitespace

\ D: matches any non-numeric characters

\ B: Location not match any beginning or end of a word

[A]: matching a single character

[Az]: matches any lowercase characters az a

[^ A]: matches any character except a

[^ Abc]: matches any character except abc of these letters

4, Nginx location application rules

The first to write a location, pick any one match behind, plus the url address (web path) written in curly braces eventually have to deal with the action

location [=|~|~*|^~|!~|!~*] /url/{...}

Default: no

Using field: server

The location parameters to match the needs of different URL can be used to match a regular expression string

例:location ~* .*\.jsp$ {

  proxy_pass http://tomcat_server;

}

(1)

http://www.a.com/

location = / {

Precision matching # /, can not take any of the hostname string

[configuration A ]

}

(2)

location / {

# Because all addresses starting with /, so this rule will match all requests

# But regular and will give priority to the longest string match

[configuration B ]

}

(3)

location / documents/ {

# Matches any address beginning to documents, in line with later matches, but also to continue the search down

# Only the back of the regular expression does not match that will be using this one

[configuration C ]

}

(4)

location ~  / documents/Abc {

# Matches any address beginning to documents, in line with later matches, but also to continue the search down

# Only the back of the regular expression does not match that will be using this one

[configuration CC ]

}

(5)

location ^~ /images/ {

# Match any addresses that begin with images, matching in line with the future, we will continue to search down

[configuration D ]

}

(6)

location ~*\.(gif|jpg|jpeg) {

# Matches all gif, jpg or jpeg ending request

# However, the picture all requests / images / under will be config D process, because ^  ~ can not reach this one regular

[configuration E ]

}

(7)

location  /images/ {

# Characters to match / images /, continue down, you will find there is ^ ~

[configuration F ]

}

(8)

location /images/abc {

# Longest string match to / images / abc, continue down, will find that the presence of ^ ~

[configuration G ]

}

5, matching sequential priority:

(Location =)> (location full path)> (location ^ ~ Path)> (location ~, ~ * regular order)> (LOCATION initial path portion)> (/)

6, experiments (need two virtual machines)

Be sure to install the first virtual machine nginx

Installation on a second virtual machine set up to ensure good LAMP 

(1) on the second virtual machine: [root @ localhost ~] # rpm -q nfs-utils rpcbind // Access nfs-utils rpcbind both packages are not installed

[root @ localhost ~] # mkdir / wwwroot         // create a file
[root @ localhost ~] # / Exports vim / etc      // add the following

/wwwroot 192.168.200.112  (ro)  

[root@localhost ~]# systemctl restart rpcbind
[root@localhost ~]# systemctl restart nfs

(2) [root @ localhost ~] # cd / wwwroot /           // add an image in it

rz

(3) in a first virtual machine:

[root @ localhost ~] # cd / usr / local / nginx / HTML / ImagesRF Royalty Free /          // look there are pictures on the second virtual machine added

[root @ localhost HTML] # vim index.html           // add the following (the picture added to the list)

<img src="images/wyb.jpg" />

(4) on page visits: 192.168.200.112

 

Guess you like

Origin www.cnblogs.com/990624lty-jhc/p/11554897.html