digerati
digerati

Reputation: 85

nginx match location with regex

I have been trying to figure out whats wrong with my regex or nginx config. I have the following location block in my nginx config

location ~ /v1/(tests|my/.*/tests|your/.*/test|our/.*/testers) {
   proxy_pass http://127.0.0.1:8000;
}

Nginx is running on port 8080 and i have a simple test web server running on port 8000. I was testing this with the following paths

I was wondering why this is, since i was matching with my/.*/tests, which should have matched empty string too? Am i missing something?

Appreciate the help!

Upvotes: 1

Views: 5074

Answers (1)

Richard Smith
Richard Smith

Reputation: 49702

nginx normalises the URI before performing tests (such as regex). Part of the normalisation process is to fold consecutive /s into a single /.

The result is that my/tests is not a valid match for your regex.

Upvotes: 1

Related Questions