Home  >  Q&A  >  body text

nginx reverse proxy regular expression configuration problem

My nginx reverse proxy configuration is as follows:

location ^~ /a(pi|uth) {
    proxy_pass http://localhost:3000;

    # Proxy Settings
    proxy_set_header    HOST    $host;
    proxy_set_header    X-Real-IP   $remote_addr;
    proxy_set_header    X-Forwarded-For     $proxy_add_x_forwarded_for;
    ...
}

Hope that requests from /api/* and /auth/* are sent to port 3000, but it seems that the matching is not successful. I think there should be no problem with regular expressions

javascript/a(pi|uth)/.test('api') // true

I directly location ^~ /api can be matched, but it doesn’t work if I use regular expressions. I don’t know what’s going on

伊谢尔伦伊谢尔伦2713 days ago495

reply all(1)I'll reply

  • PHPz

    PHPz2017-05-16 17:25:02

    location ~* /a(pi|uth)
    

    After looking at it, it seems that ^~does not match the regular expression

    reply
    0
  • Cancelreply