0

my main domain is example.com

i have implemented MEAN project in main domain, now i want example.com/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.com;

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.com;

location / {

#proxy_pass https://example.com;

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

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 Apr 9 '20 at 14:20
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.com/blog/ . When wp had to make some json operations, with js calling urls like https://example.com/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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.