Nginx host wordpress无法找到restapi的问题

server {
        listen        80;
        server_name  localhost;
        root   "C:/Users/pc/source/repo/WordPress";
        location / {
            index index.php index.html;
            error_page 400 /error/400.html;
            include C:/Users/pc/source/repo/WordPress/nginx.htaccess;
            autoindex  off;
        }

        location ~ ^/wp-json/ {
            rewrite ^/wp-json/(.*?)$ /?rest_route=/$1 last;
        }
        
        location ~ \.php(.*)$ {
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.php;
            fastcgi_split_path_info  ^((?U).+\.php)(/?.+)$;
            fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
            fastcgi_param  PATH_INFO  $fastcgi_path_info;
            fastcgi_param  PATH_TRANSLATED  $document_root$fastcgi_path_info;
            include        fastcgi_params;
        }
}

在nginx配置文件中,插入标注代码,把这个route规则的请求地址 原封不动 的映射到php服务,即可解决该问题。

posted @ 2021-04-12 18:10  崩溃大喵  阅读(206)  评论(0)    收藏  举报