首页 > 解决方案 > Nginx 位置正则表达式以匹配不同的路径

问题描述

是否可以为匹配api或定义的字符数定义一些正则表达式?目前我有这个:参见示例的评论。

server {
 listen       80;
 server_name  example.com;
 
 location / {
  # This one should either match for urls like where last path is a range from A-z and 0-9 totally random but only 2 chars. AND everything else with example.com/api/… but not example.com/A5/foo
  # Match: example.com/A5, example.com/3C, example.com/api/register
  # No match: example.com, example.com/ABC123 
  proxy_pass      http://localhost:3000;
 }

 location / {
  # Everything else should match here…
  proxy_pass      http://localhost:5000;
 }
}

标签: regexnginxlocationmatch

解决方案


推荐阅读