0

I have a wordpress site located in /var/www/example.com/sites/public. I want this wordpress site to be accessed through example.com/_api. How can I do this? Here is the config I have at this moment:

    server {
            listen 80;
            server_name example.com;
            root /var/www/example.com/site/public;
            location /_api/ {
                    index index.php;
                    try_files $uri $uri/ /index.php?$args;
            }
            location ~ \.php$ {
                    try_files $uri =404;
                    fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock;
                    fastcgi_index index.php;
                    fastcgi_intercept_errors on;
                    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
                    include fastcgi_params;
            }
    }

I get 403 if I access example.com, which makes sense as there is no index file for root. But if I go to example.com/_api or example.com/_api/index.php, I get 404 error. What is the problem in this config? In what directory does nginx search in this config that index.php is not found?

  • Is there any reason you can't install WordPress to the /_api/ directory? – Paul Sep 19 '16 at 7:39
0

I'd just use a proxy_pass directive. Something like this

location /_api/ {
  proxy_pass http://www.example.com/whatever
}

Alternate you could just move Wordpress to the _api directory and then configure as follows

try_files $uri $uri/ /blog/index.php?$args;

There's probably a dozen different ways to do this, someone may come up with a better one.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.