【原创】运维基础之Nginx(3)location和rewrite

时间:2023-03-09 17:12:44
【原创】运维基础之Nginx(3)location和rewrite

nginx location

  • =:精确匹配(必须全部相等)
  • ~:大小写敏感,正则匹配
  • ~*:忽略大小写,正则匹配
  • ^~:只需匹配uri部分,精确匹配
  • @:内部服务跳转,精确匹配

优先级:

  1. Exact match =
  2. Forward match ^~ /
  3. Case sensitive regex ~ /
  4. Case insensitive regex ~*
  5. Path match /

规则

精确匹配规则是“最大前缀”.
正则匹配规则是“顺序匹配”,只要匹配到第一个就停止后面的匹配.
通用匹配 “/”最后匹配

nginx rewrite

rewrite ^(.*)$ /other/path/or/server/$1 break;