简体   繁体   中英

Woocommerce REST API - Nginx - Error 404 Not Found

I'm trying to use the Woocommerce (v 3.5.4) Rest Api on my VPS ( debian 9, Nginx ).

Everything works well in my local machine ( windows 10, XAMPP ).

wpbop/ is the folder (var/www/wpbop/) where the wordpress files are stored.

The next basic URL in a browser should send the endpoints of the API (no need of athentication for this first step) : http:// my-public-ip /wpbop/wp-json/wc/v3

Or a curl in command line

curl http://127.0.0.1/wpbop/wp-json/wc/v3

in both cases, i get error 404 Not Found.

I can acces to the blog / admin blog without any problems ( http:// my-public-ip /wpbop )

My permalinks are set on "Postname" in wordpress admin panel, this is recommanded by many people in same case.


EDIT - SOLUTION :

Since my Wordpress installation is in a sub-domain,

try_files $uri $uri/ /index.php$is_args$args;

can't find index.php. Just change this line by :

try_files $uri $uri/ /wpbop/index.php$is_args$args;

and it works !


Perhaps problem is coming from my Nginx conf file ?

server {
  server_name localhost;
  listen 80;
  root /var/www;

    location /wpbop {

        index index.php;

        access_log /var/log/nginx/blog.access.log;
        error_log /var/log/nginx/blog.error.log;

        try_files $uri $uri/ /index.php$is_args$args;

            add_header 'Access-Control-Allow-Origin' '*';
            add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';

        location ~ \.php$ {
            try_files $uri =404;
            fastcgi_index index.php;
            fastcgi_pass 127.0.0.1:7000;
            fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
            include /etc/nginx/fastcgi_params;
        }
    }
}

I tried many things without any results, and I'm stuck for several days. Can someone help me ? Thanks for reading me.

This case need a simple fix in the NGINX configuration file. This is related to the path of my wordpress installation.

Since my Wordpress installation is in a sub-domain,

try_files $uri $uri/ /index.php$is_args$args;

--> can't find index.php. Just change this line by :

try_files $uri $uri/ /wpbop/index.php$is_args$args;

Move root /var/www/; by one level up (to server context). It is not being inherited.

when you get 404 code. try to access http://yoursite/?rest_route=/wp/v2/posts

Official documents https://developer.wordpress.org/rest-api/key-concepts

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM