Linux version nginx conf has issue with wordpress REST API
I was getting an error while restoring a backup of WordPress site.
Console show this error
Object { cid: "c4", attributes: {…}, _changing: false, _previousAttributes: {…}, changed: {}, _pending: false, requireForceForDelete: true, apiRoot: "https://myphp.test/wp-json/", versionString: "wp/v2/", _events: {…} }
wp-api.min.js:2:10286
SyntaxError: JSON.parse: unexpected character at line 1 column 1 of the JSON data main-bbbda89e.js:1153:164590
SyntaxError: JSON.parse: unexpected character at line 1 column 1 of the JSON data main-bbbda89e.js:1153:165033
SyntaxError: JSON.parse: unexpected character at line 1 column 1 of the JSON data main-bbbda89e.js:1153:165033
SyntaxError: JSON.parse: unexpected character at line 1 column 1 of the JSON data main-bbbda89e.js:1153:165033
After asking ChatGPT it says there is issue in nginx conf file below was the original
server
{
listen 80;
listen 443 ssl http2;
server_name myphp.test www.myphp.test;
index index.php index.html index.htm default.php default.htm default.html;
root "/data/phpwebstudy-sites/myphp.test";
ssl_certificate "/home/shahi/.config/PhpWebStudy/server/CA/1738932715594/CA-1738932715594.crt";
ssl_certificate_key "/home/shahi/.config/PhpWebStudy/server/CA/1738932715594/CA-1738932715594.key";
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:HIGH:!aNULL:!MD5:!RC4:!DHE;
ssl_prefer_server_ciphers on;
ssl_session_cache shared:SSL:10m;
ssl_session_timeout 10m;
#PHP-INFO-START
include enable-php-83.conf;
#PHP-INFO-END
#REWRITE-START URL重写规则引用,修改后将导致面板设置的伪静态规则失效
include /home/shahi/.config/PhpWebStudy/server/vhost/rewrite/myphp.test.conf;
#REWRITE-END
#禁止访问的文件或目录
location ~ ^/(\.user.ini|\.htaccess|\.git|\.svn|\.project|LICENSE|README.md)
{
return 404;
}
#一键申请SSL证书验证目录相关设置
location ~ \.well-known{
allow all;
}
location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
{
expires 30d;
error_log off;
access_log /dev/null;
}
location ~ .*\.(js|css)?$
{
expires 12h;
error_log off;
access_log /dev/null;
}
access_log /home/shahi/.config/PhpWebStudy/server/vhost/logs/myphp.test.log;
error_log /home/shahi/.config/PhpWebStudy/server/vhost/logs/myphp.test.error.log;
}
Here is the modified version from ChatGPT
server {
listen 80;
listen 443 ssl http2;
server_name myphp.test www.myphp.test;
index index.php index.html index.htm default.php default.htm default.html;
root "/data/phpwebstudy-sites/myphp.test";
ssl_certificate "/home/shahi/.config/PhpWebStudy/server/CA/1738932715594/CA-1738932715594.crt";
ssl_certificate_key "/home/shahi/.config/PhpWebStudy/server/CA/1738932715594/CA-1738932715594.key";
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:HIGH:!aNULL:!MD5:!RC4:!DHE;
ssl_prefer_server_ciphers on;
ssl_session_cache shared:SSL:10m;
ssl_session_timeout 10m;
#PHP-INFO-START
include enable-php-83.conf;
#PHP-INFO-END
#REWRITE-START URL重写规则引用,修改后将导致面板设置的伪静态规则失效
include /home/shahi/.config/PhpWebStudy/server/vhost/rewrite/myphp.test.conf;
#REWRITE-END
# WordPress rewrite rules (fixes REST API and permalinks)
location / {
try_files $uri $uri/ /index.php?$args;
}
# PHP handling
location ~ \.php$ {
include fastcgi_params;
fastcgi_pass 127.0.0.1:9000; # Adjust if using a different PHP-FPM port
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
# Block access to sensitive files
location ~ ^/(\.user.ini|\.htaccess|\.git|\.svn|\.project|LICENSE|README.md) {
return 404;
}
# Let's Encrypt SSL certificate verification directory
location ~ /\.well-known {
allow all;
}
# Static file caching
location ~* \.(gif|jpg|jpeg|png|bmp|swf)$ {
expires 30d;
error_log off;
access_log /dev/null;
}
location ~* \.(js|css)?$ {
expires 12h;
error_log off;
access_log /dev/null;
}
access_log /home/shahi/.config/PhpWebStudy/server/vhost/logs/myphp.test.log;
error_log /home/shahi/.config/PhpWebStudy/server/vhost/logs/myphp.test.error.log;
}
Now it's working.
Your app mention it has Email Server Mailpit but for Linux version 4 doesn't have it, please update the Linux version. 🙏
In Debian 12 after removing and deleting ~/.config/PhpWebStudy, I installed it again, PhpMyAdmin login issue arise, so I have to create the config.ini.php file and other setting need to be done. Now at least everything works.
Please add Email Server Mailpit for Linux version 🙏
Linux lasted version has released. download and try https://flyenv.com/download.html