Woocommerce REST API-Nginx-未找到错误404

时间:2019-02-20 20:32:51

标签: rest nginx woocommerce http-status-code-404

我正在尝试在我的VPS( debian 9,Nginx )上使用 Woocommerce (v 3.5.4) Rest Api

一切都可以在我的本地计算机上正常运行( Windows 10,XAMPP )。

wpbop / 是存储wordpress文件的文件夹(var / www / wpbop/)。

浏览器中的下一个基本URL应该发送API的终结点(第一步无需进行加密): http:// my-public-ip / wpbop / wp-json / wc / v3

或者在命令行中卷曲

卷曲http://127.0.0.1/wpbop/wp-json/wc/v3

在两种情况下,我都收到错误404 Not Found。

我可以顺利访问博客/管理博客( http:// my-public-ip / wpbop

我的永久链接是在wordpress管理面板中的“邮政名称”上设置的,在许多情况下,很多人都建议这样做。


编辑-解决方案:

由于我的Wordpress安装位于子域中,

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

找不到index.php。只需通过以下方式更改此行:

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

,它有效!


问题可能出在我的Nginx conf文件中吗?

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;
        }
    }
}

我尝试了很多事情,没有任何结果,但是我被困了几天。有人能帮我吗 ? 感谢您的阅读。

3 个答案:

答案 0 :(得分:1)

这种情况需要在NGINX配置文件中进行简单修复。这与我的wordpress安装路径有关。

由于我的Wordpress安装位于子域中,

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

->找不到index.php。只需更改此行:

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

答案 1 :(得分:0)

root /var/www/;向上移动一级(到server上下文)。它没有被继承。

答案 2 :(得分:0)

当您收到 404 代码时。尝试访问 http://yoursite/?rest_route=/wp/v2/posts

官方文件https://developer.wordpress.org/rest-api/key-concepts