My project directory structure is as follows:
/var/www/mysite/
backend/
frontend/
where frontend/
contains simple html and js files, and backend/
is a wordpress site. I expose wordpress data to a REST api endpoint for the frontend.
I want to have mysite.com show the html/js files and all REST api calls are made to mysite.com/api
which are the wordpress site files. (so mysite.com/api/wp-admin
will also work as normal).
I am having trouble configuring nginx to make this possible. This is my current configuration:
server {
listen *:80;
server_name mysite.com www.mysite.com;
access_log /var/log/nginx/mysite.access.log;
error_log /var/log/nginx/mysite.error.log;
root /var/www/mysite/frontend;
location / {
index index.html index.htm index.php;
}
location ^~ /api {
root /var/www/mysite/backend;
index index.php;
try_files $uri $uri/ /../backend/index.php?$args;
location ~ \.php$ {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
# NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini
# With php5-cgi alone:
fastcgi_pass 127.0.0.1:9000;
# With php5-fpm:
#fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
}
}
sendfile off;
}
This just downloads the index.php file from wordpress when I try to access the URL mysite.com/api. Any help is appreciated, thanks.