admin管理员组文章数量:1308305
my main domain is example
i have implemented MEAN project in main domain, now i want example/blog for wordpress setup.
i have done following configuartion in nginx config file
server {
listen 80 default_server;
listen [::]:80 default_server;
server_name example;
return 301 https://$host$request_uri;
}
server {
listen 443 ssl http2 default_server;
listen [::]:443 ssl http2 default_server;
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
server_tokens off;
root /home/ubuntu/example/dist;
server_name example;
location / {
#proxy_pass ;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header Host $http_host;
proxy_pass http://127.0.0.1:3000;
}
location /blog {
alias /var/www/html/;
index index.php index.html index.htm;
try_files $uri $uri/ @blog;
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_param SCRIPT_FILENAME $request_filename;
fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;
}
location ~(ogg|ogv|svg|svgz|eot|otf|woff|mp4|ttf|css|rss|atom|js|jpg|jpeg|gif|png|ico|zip|tgz|gz|rar|bz2|doc|xls|exe|ppt|tar|mid|midi|wav|bmp|rtf)
{
try_files $uri $uri/ =404;
}
}
location @blog {
rewrite /blog/(.*)$ /blog/index.php?q=$uri$args;
}
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;
}
}
all are working file but only wp-json url return 404
my main domain is example
i have implemented MEAN project in main domain, now i want example/blog for wordpress setup.
i have done following configuartion in nginx config file
server {
listen 80 default_server;
listen [::]:80 default_server;
server_name example;
return 301 https://$host$request_uri;
}
server {
listen 443 ssl http2 default_server;
listen [::]:443 ssl http2 default_server;
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
server_tokens off;
root /home/ubuntu/example/dist;
server_name example;
location / {
#proxy_pass https://example;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header Host $http_host;
proxy_pass http://127.0.0.1:3000;
}
location /blog {
alias /var/www/html/;
index index.php index.html index.htm;
try_files $uri $uri/ @blog;
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_param SCRIPT_FILENAME $request_filename;
fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;
}
location ~(ogg|ogv|svg|svgz|eot|otf|woff|mp4|ttf|css|rss|atom|js|jpg|jpeg|gif|png|ico|zip|tgz|gz|rar|bz2|doc|xls|exe|ppt|tar|mid|midi|wav|bmp|rtf)
{
try_files $uri $uri/ =404;
}
}
location @blog {
rewrite /blog/(.*)$ /blog/index.php?q=$uri$args;
}
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;
}
}
all are working file but only wp-json url return 404
Share Improve this question edited Apr 9, 2020 at 14:01 fuxia♦ 107k38 gold badges255 silver badges459 bronze badges asked Apr 9, 2020 at 13:32 Amit JagtapAmit Jagtap 11 bronze badge 1- Hello! Can you indent your Nginx config? It's a little difficult to read, indenting will make it easier to write answers :) Use the edit link underneath the tags. Also, I'm not familiar with MEAN, do you have a link to an explainer? – Tom J Nowell ♦ Commented Apr 9, 2020 at 14:20
1 Answer
Reset to default 2I hope you solved this problem since April 2020.
I got some kind of same trouble with the wordpress php files being accessible throw https://example/blog/ . When wp had to make some json operations, with js calling urls like https://example/blog/wp-json/wp/v2/posts/23?_locale=user for instance, it used to throw a 404 error.
I solved this adding an extra rule in the nginx conf file :
# Rule to solve the json-error problem
location /blog/wp-json {
try_files $uri $uri/ /blog/index.php?q=$uri$args;
}
I hope this helps you.
Marc.
本文标签: blogwpjson nginx return 404
版权声明:本文标题:blogwp-json nginx return 404 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741842053a2400559.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论