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
Add a comment  | 

1 Answer 1

Reset to default 2

I 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