1.Location后什么都不带直接指定目录
root@Nginx conf.d\]# vim vhosts.conf server { listen 80; server_name lee.timinglee.org; location /null { return 200 "/null-1"; } } \[root@Nginx conf.d\]# curl lee.timinglee.org/null/ /null-1 \[root@Nginx conf.d\]# curl lee.timinglee.org/NULL/ \ \
\404 Not Found\ \ \ \\ \404 Not Found\
\
\nginx/1.28.1\ \ \
2.location 后用 =
root@Nginx conf.d\]# vim vhosts.conf server { listen 80; server_name lee.timinglee.org; location /null { return 200 "null-1"; } location = /null { #精确匹配到此结束 return 200 "null-2"; } location \~ /null { return 200 "null-3"; } } \[root@Nginx conf.d\]# nginx -s reload \[root@Nginx conf.d\]# curl lee.timinglee.org/null null-2
root@Nginx conf.d\]# vim vhosts.conf server { listen 80; server_name lee.timinglee.org; location /null { return 200 "null-1"; } location = /null { return 200 "null-2"; } location \~ /null { return 200 "null-3"; } location \^\~ /lee { return 200 "lee"; } } \[root@Nginx conf.d\]# nginx -s reload lee \[root@Nginx conf.d\]# curl lee.timinglee.org/lee lee \[root@Nginx conf.d\]# curl lee.timinglee.org/test/lee \ \
\404 Not Found\ \ \ \\ \404 Not Found\
\
\nginx/1.28.1\ \ \ \[root@Nginx conf.d\]# curl lee.timinglee.org/leeab/test lee
root@Nginx conf.d\]# vim vhosts.conf server { listen 80; server_name lee.timinglee.org; location /null { return 200 "null-1"; } location = /null { return 200 "null-2"; } location \~ /null { return 200 "null-3"; } location \^\~ /lee { return 200 "lee"; } location \~ /timing/ { return 200 "timing"; } } \[root@Nginx conf.d\]# nginx -s reload \[root@Nginx conf.d\]# curl lee.timinglee.org/timinga/ timing \[root@Nginx conf.d\]# curl lee.timinglee.org/timing/ timing \[root@Nginx conf.d\]# curl lee.timinglee.org/a/timing/ timing \[root@Nginx conf.d\]# curl lee.timinglee.org/a/timinga/ timing \[root@Nginx conf.d\]# curl lee.timinglee.org/a/atiming/ \ \
\404 Not Found\ \ \ \\ \404 Not Found\
\
\nginx/1.28.1\ \ \
5.location 后用"~*"
root@Nginx conf.d\]# vim vhosts.conf server { listen 80; server_name lee.timinglee.org; location /null { return 200 "null-1"; } location = /null { return 200 "null-2"; } location \~ /null { return 200 "null-3"; } location \^\~ /lee { return 200 "lee"; } location \~ /timing/ { return 200 "timing"; } location \~\* /timinglee { return 200 "timinglee"; } } \[root@Nginx conf.d\]# nginx -s reload \[root@Nginx conf.d\]# curl lee.timinglee.org/Timinglee/ timinglee \[root@Nginx conf.d\]# curl lee.timinglee.org/timinglee/ timinglee \[root@Nginx conf.d\]# curl lee.timinglee.org/timinglee/a timinglee \[root@Nginx conf.d\]# curl lee.timinglee.org/a/timinglee/a timinglee \[root@Nginx conf.d\]# curl lee.timinglee.org/a/atiminglee/a \ \
\404 Not Found\ \ \ \\ \404 Not Found\
\
\nginx/1.28.1\ \ \ \[root@Nginx conf.d\]# curl lee.timinglee.org/a/timingleea/a timinglee \[root@Nginx conf.d\]# curl lee.timinglee.org/a/Timinglee/a timinglee
6.location 后用"\"
root@Nginx conf.d\]# vim vhosts.conf server { listen 80; server_name lee.timinglee.org; location /null { return 200 "null-1"; } location = /null { return 200 "null-2"; } location \~ /null { return 200 "null-3"; } location \^\~ /lee { return 200 "lee"; } location \~ /timing/ { return 200 "timing"; } location \~\* /timinglee { return 200 "timinglee"; } location \~\* \\.(img\|php\|jsp)$ { return 200 "app"; } } \[root@Nginx conf.d\]# nginx -s reload \[root@Nginx conf.d\]# curl lee.timinglee.org/test.php app \[root@Nginx conf.d\]# curl lee.timinglee.org/test.jsp app