In the default server segment of/usr/local/nginx/conf/nginx.conf, leave the default location information (previously tested location configuration removed):
Location/{ root html; Index index.html index.htm; }
Create the image directory under/var/www:
[Email protected] ~]# cd/var/www[[email protected] www]# mkdir image
Download or transfer a picture in this directory using wget or ftp: test.jpg
Modify/usr/local/nginx/html/index.html, plus
[Email protected] nginx]# vim html/index.html <! DOCTYPE html>
Smooth restart Nginx.
Because there is no image directory under the/usr/local/nginx/html/directory, when you access 192.168.254.100, the pictures on the page cannot be displayed:
Direct access to the image address:
At this point, a regular matching location configuration (2nd) is added under the location configuration, at which point the location is configured as:
Location/{ root html; Index index.html index.htm; } Location ~ image { root/var/www/; Index index.html;
Smooth restart Nginx.
To access the http://192.168.254.100/image/test.jpg, the regular match and the generic match are matched to the URI at the time of the precedence match:
The picture in the/var/www/image directory is displayed.
Direct access to Http://192.168.254.100/image/test.jpg:
The matching process is: the image in the regular match matches the/image/test.jpg in the URI, then the regular match works, and the real access is/var/www/images/test.jpg
Again, when more than one common match can be matched to a URI, which match can really work (compare 1th and 2nd)?
/usr/local/nginx/conf/nginx.conf:
Location/{ root html; Index index.html index.htm; } Location/foo { root /var/www; Index index.htm index.html; } Location ~ image { root/var/www/; Index index.html; }
At this time the/var/www directory has foo directory, below the file Index.htm:i ' m/var/www/index.htm
For the URI "/foo", the two location of the Patt can match, that "/" and "/foo" can be left prefix matching "/foo",
Visit Http://192.168.254.100/foo:
That
Location/foo { root /var/www; Index index.htm index.html; }
Play a role because "/foo" is longer, so the location of "/foo" is used to match.
Nginx notes and summaries (7) Location: regular match