1

I am trying to build an nginx configuration for an Single Page Application that accesses PHP code through an API. What I am trying to do is map an ajax call of the form /api/xxx through to a file in project_directory/php/xxx.php

So I have a location block like this:-

location ~* /api/(\w+) { root /path/to/project_directory; try_files /php/$1.php =404; ... call fastcgi gateway } 

I need to set up $fastcgi_script_name so that it will set all the correct environment variables. Does it do this when try files matches?

1 Answer 1

1

You need to ignore $fastcgi_script_name and replace any fastcgi_param directives with your re-mapped value. Your location block might start like:

location ~* /api/(\w+) { root /path/to/project_root; set $my_script_name /php/$1; try_files $my_script_name =404; fastcgi_param SCRIPT_NAME $my_script_name; fastcgi_param SCRIPT_FILENAME $document_root$my_script_name; ... } 

Obviously commenting out any conflicting fastcgi_param directives.

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.