Reputation: 10111
I'm having a lot of trouble setting up my nginx server with my PHP RESTful API. I have the following blocks in my server{}
block:
location / {
rewrite ^/v1/* /v1/api.php last;
rewrite ^/* /index.php last;
}
location * .*\.php$ {
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_pass 127.0.0.1:9000;
}
However.. these seem not to be functioning properly. Basicly, I want every URL starting with /v1/
to be rewritten to /v1/api.php
, and anything else to /index.php
.
This seems to be working partially. Sometimes it actually does go to api.php
, but sometimes it just seems to download the file instead of processing it through PHP-FPM. How would I fix this?
Upvotes: 1
Views: 117
Reputation: 42799
Downloading a file means not being passed to the php engine, so I assume the problem is in that block definition replace
location * .*\.php$ {
with
location ~ \.php$ {
And probably it will work.
Upvotes: 1