2

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?

Mr.D
  • 7,353
  • 13
  • 60
  • 119
  • What does it mean continue to /service/{uuid} ? You have ways of capturing the string and proxy_pass or redirect to service/auth/{uid}. I feel like it's possible to do it if you control the return code of /service/auth/{uuid}/ but it's a whole 3 proxy_pass and different configurations. Can you tell me what http code does auth return on successful auth and on non successful one? – flaixman Oct 02 '19 at 08:40
  • @flaixman It will return 200 if success and 401 if fails – Mr.D Oct 02 '19 at 08:49
  • @Mr.D were you able to find a solution? I'm stuck in a similar situation where I need a capture group (regex) from within the location directive to use within proxy_pass. It works when there is no auth_request, but not when I use auth_request. – Rads Jan 01 '21 at 04:01

1 Answers1

0

You can capture it using regex.

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

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

Alex C
  • 171
  • 1
  • 11