location 指令说明
location [ = | ~ | ~* | ^~ ] uri {
}
- = :用于不含正则表达式的 uri 前,要求请求字符串与 uri 严格匹配,如果匹配成功,就停止继续向下搜索并立即处理该请求。
- ~ :用于表示 uri 包含正则表达式,并且区分大小写。
- ~* :用于表示 uri 包含正则表达式,并且不区分大小写。
- ^~ :用于不含正则表达式的 uri 前,要求 Nginx 服务器找到标识 uri 和请求字符串匹配度最高的 location 后,立即使用此 location 处理请求,而不再使用 location 块中的正则 uri 和请求字符串做匹配。
注意:如果 uri 包含正则表达式,则必须要有 ~ 或者 ~* 标识。
192.168.0.107:80 -> 127.0.0.1:8080
worker_processes 1;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
server {
listen 80;
server_name 192.168.0.107;
location / {
proxy_pass http://127.0.0.1:8080;
}
}
}

http://192.168.0.107:9001/docs/ -> 127.0.0.1:8080
http://192.168.0.107:9001/examples/ -> 127.0.0.1:8081
worker_processes 1;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
server {
listen 9001;
server_name 192.168.0.107;
location / {
root html;
index index.html index.htm;
}
location ~ /docs/ {
proxy_pass http://127.0.0.1:8080;
}
location ~ /examples/ {
proxy_pass http://127.0.0.1:8081;
}
}
}

https://nginx.org/en/docs/http/ngx_http_core_module.html#location