Home  >  Q&A  >  body text

nginx - regular expression matching route writing method

If you want to match some regular routes, use a proxy

location /chat/ {
        proxy_set_header Host $host;
        proxy_set_header X-Forwarded-For $remote_addr;
        proxy_set_header  X-Real-IP  $remote_addr;
        proxy_pass http://newmessage;
 }

I want all routes starting with /chat/ to be proxied, such as /chat/send/. The above way of writing will work.

But want to add multiple matches

location /chat/ or /a/ or /b/ {

I checked some information online

location /(chat|a|b)/ {

This doesn't work either.

阿神阿神2712 days ago742

reply all(1)I'll reply

  • phpcn_u1582

    phpcn_u15822017-05-16 17:28:42

    Add a tilde

    location ~ /(chat|a|b)/ {
    

    reply
    0
  • Cancelreply