Mr.D
Mr.D

Reputation: 7873

Nginx, auth_request with dynamic path param

My web service has serveral urls like this:

POST /service
GET /service/a59aeaba-7f3f-4826-896a-aeb48e1db256
POST /service/a59aeaba-7f3f-4826-896a-aeb48e1db256/action1
POST /service/a59aeaba-7f3f-4826-896a-aeb48e1db256/action2
...

Also, I have different url that has authorization check, which will return code 200 if success and will return 401 if failed:

GET /service/auth/a59aeaba-7f3f-4826-896a-aeb48e1db256

Now there this uuid value inside path as parameter, which is dynamic value.

I don't know how to capture /service/{uuid}/* url and make auth_request to /service/auth/{uuid} then, after successful response continue to /service/{uuid}

Is it even possible to do this in Nginx?

Upvotes: 2

Views: 955

Answers (1)

Alex C
Alex C

Reputation: 171

You can capture it using regex.

location ~* ^/service/(?<uuid>.+)/ {

Now uuid is in named group, which you can refer later as ${uuid}

Upvotes: 0

Related Questions