Wednesday, April 10, 2019

php - Get nginx location wildcard inside location block?

I am trying to set up an API where I can access API "foobar" through the URL http://my-apis.com/foobar/route. This is what I have so far:




location ~ ^/foobar(/.*)$ {
root /var/www/mysite/foobar/public;

... more fastcgi stuff ...

fastcgi_param SCRIPT_FILENAME $document_root/index.php$1;
fastcgi_param PATH_INFO $fastcgi_path_info;
}



The API is routing to a Slim framework application and currently it successfully routes to the correct index.php, showing an nginx 404/403 whenever the URL does not start with /foobar. However the route passed to Slim (which looks like it's represented by $1 on line 6) is still the full /foobar/route. This means I have to append all all my Slim routes with /foobar, which, although I can use a Slim group, is still a pain. I would like to be able to pass just the /route bit to Slim.



Is there a way I can extract just the wildcard-matched bit of the location directive? Since $1 gives the full route. Alternatively I might be able to do this with some kind of rewrite, but I don't know enough about Slim.



Any help would be much appreciated!



Thanks!

No comments:

Post a Comment

linux - How to SSH to ec2 instance in VPC private subnet via NAT server

I have created a VPC in aws with a public subnet and a private subnet. The private subnet does not have direct access to external network. S...