在WordPress下安裝了Rest API插件,卻發現無法訪問API,找了很久終於找到了一個解決方法。
原文如下:https://www.runtimego.com/136.html
我的環境:Ubuntu18.04,nginx(lnmp安裝)
第一步:修改固定鏈接
將WordPress設置中的固定鏈接為文章型,然后保存更改。
第二步:修改nginx.conf文件
遠程連接我的服務器
進入lnmp安裝的 Nginx 目錄: /usr/local/nginx/
修改/usr/local/nginx/conf/nginx.conf文件
好像也有的是/usr/local/nginx/nginx.conf
修改這個文件,在server中加入以下幾行進行重定向
if (-f $request_filename/index.html){
rewrite (.*) $1/index.html break;
}
if (-f $request_filename/index.php){
rewrite (.*) $1/index.php;
}
if (!-f $request_filename){
rewrite (.*) /index.php;
}
rewrite /wp-admin$ $scheme://$host$uri/ permanent;
#這行是為了防止打開后台、插件頁等打不開的。
第三步:重啟nginx
修改完之后先檢查nginx.conf文件的可用性。
/usr/local/nginx/sbin/nginx -t
其中/usr/local/nginx換成自己的nginx地址
這樣子就是正確了。
然后重啟nginx
/usr/local/nginx/sbin/nginx -s reload
好了現在打開 你的wp地址/wp-json/wp/v2/posts就不是404了