我正在使用非常棒的WP-API(https://github.com/WP-API/WP-API)来检索我网站上的帖子。它在我的本地开发环境(apache)和Apache服务器上运行良好。但是在我未来的生产服务器上使用nginx却没有。
http://2013.thomastraum.com/wp-json/posts
此查询返回唯一的测试帖子,这是正确的行为,但下面的查询将不起作用,所有查询参数都将被忽略,并返回与上述相同的结果。预期的行为是它返回页面,例如'about'和'contact'页面。
http://2013.thomastraum.com/wp-json/posts?type[]=page
您可以在此处看到正确的查询结果:
http://stage.thomastraum.com/wp-json/posts?type[]=page
正如我所说,唯一的区别是网络服务器。这是我的nginx配置文件。我的nginx版本是nginx/1.1.19
server {
# .domain.com will match both domain.com and anything.domain.com
server_name 2013.thomastraum.com;
# It is best to place the root of the server block at the server level, and not the location level
# any location block path will be relative to this root.
root /var/www/2013.thomastraum.com;
# It's always good to set logs, note however you cannot turn off the error log
# setting error_log off; will simply create a file called 'off'.
access_log /var/log/nginx/2013.thomastraum.com.log;
error_log /var/log/nginx/2013.thomastraum.com.error.log;
# This can also go in the http { } level
index index.html index.htm index.php;
location / {
# if you're just using wordpress and don't want extra rewrites
# then replace the word @rewrites with /index.php
# try_files $uri $uri/ index.php;
try_files $uri $uri/ /index.php?q=$request_uri;
}
location @rewrites {
# Can put some of your own rewrite rules in here
# for example rewrite ^/~(.*)/(.*)/? /users/$1/$2 last;
# If nothing matches we'll just send it to /index.php
rewrite ^ /index.php last;
}
# This block will catch static file requests, such as images, css, js
# The ?: prefix is a 'non-capturing' mark, meaning we do not require
# the pattern to be captured into $1 which should help improve performance
location ~* \.(?:ico|css|js|gif|jpe?g|png)$ {
# Some basic cache-control for static files to be sent to the browser
expires max;
add_header Pragma public;
add_header Cache-Control "public, must-revalidate, proxy-revalidate";
}
# remove the robots line if you want to use wordpress' virtual robots.txt
location = /robots.txt { access_log off; log_not_found off; }
location = /favicon.ico { access_log off; log_not_found off; }
# this prevents hidden files (beginning with a period) from being served
location ~ /\. { access_log off; log_not_found off; deny all; }
location ~ \.php {
fastcgi_param QUERY_STRING $query_string;
fastcgi_param REQUEST_METHOD $request_method;
fastcgi_param CONTENT_TYPE $content_type;
fastcgi_param CONTENT_LENGTH $content_length;
fastcgi_param SCRIPT_NAME $fastcgi_script_name;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param REQUEST_URI $request_uri;
fastcgi_param DOCUMENT_URI $document_uri;
fastcgi_param DOCUMENT_ROOT $document_root;
fastcgi_param SERVER_PROTOCOL $server_protocol;
fastcgi_param GATEWAY_INTERFACE CGI/1.1;
fastcgi_param SERVER_SOFTWARE nginx;
fastcgi_param REMOTE_ADDR $remote_addr;
fastcgi_param REMOTE_PORT $remote_port;
fastcgi_param SERVER_ADDR $server_addr;
fastcgi_param SERVER_PORT $server_port;
fastcgi_param SERVER_NAME $server_name;
fastcgi_pass 127.0.0.1:9000;
}
}
答案 0 :(得分:0)
您可以修复nginx.conf配置文件,或者也可以这种方式附加GET参数json_route
:
?json_route=/post
您也可以使用过滤器执行此操作:
?json_route=/posts?filters[s]=something
应用于您的域名,如下所示:
答案 1 :(得分:0)
正确的网址应以:
结尾?json_route=/posts&filters[s]=something
注意只使用一个问号(多个问号不是有效的网址),而是在json_route = / posts
后使用&符号答案 2 :(得分:0)
注意只使用一个问号(多个问号不是有效的网址),而是在json_route = / posts 之后使用&符号
这对我不起作用。 我用的时候: / json_route = /帖&安培;过滤[搜索] = S 我有: '过滤[搜索]'不被视为内部或外部命令, 我用的时候: /?json_route = /讯息?过滤[搜索] = S 我有: [{"代码":" json_no_route","消息":"未找到与网址和请求方法匹配的路由"}]
您对此问题有任何决定吗。