Once I installed WordPress on an Ubuntu Server operating system with a Nginx web server and when I tried to add a new article I saw an error:
Error posting. Error message: The response is not a valid JSON response.
When updating an existing article, an error was also displayed:
Update failed. Error message: The response is not a valid JSON response.
If you look at the Site Health tool (/wp-admin/site-health.php), you could see the error:
REST API returned unexpected result
404 Not Found
nginx/1.14.0 (Ubuntu)
To solve these errors, as well as to make arbitrary links work (like apache with rewrite), I opened the site configuration file in nginx (for example /etc/nginx/sites-enabled/ixnfo-com.conf) and found the standard lines:
location / {
# First attempt to serve request as file, then
# as directory, then fall back to displaying a 404.
try_files $uri $uri/ =404;
}
And replaced them with:
location / {
try_files $uri $uri/ /index.php$is_args$args;
}
Then I checked the correctness of the Nginx configuration and restarted it to apply the changes:
sudo nginx -t
sudo service nginx restart
After that, the errors disappeared.
See also my article:
Installing WordPress and Nginx