从不同路径运行Wordpress/NGINX



我正在学习NGINX,所以非常感谢您的帮助。

我有一个网站的前端作为mysite.com的根运行,现在我想从mysite.com/blog.运行wordpress

我的文件结构是:/srv/mysite/前端/srv/mysite/wordpress

这是我从nginx日志中得到的错误

2020/03/29 00:09:03 [error] 23049#23049: *39 FastCGI sent in stderr: "Primary script unknown" while reading response header from upstream, client: XXXXXXX, server: www.mysite.com, request: "GET /api HTTP/1.1", upstream: "fastcgi://unix:/run/php/php7.2-fpm.sock:", host: "mysite.com"

这是我到目前为止的nginx配置文件

listen 80 default_server;
server_name www.mysite.com mysite.com;
charset utf-8;
location ^~ /blog {
root /srv/mysite/wordpress;
}
location ~ .php$ {
fastcgi_pass unix:/run/php/php7.2-fpm.sock;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param SCRIPT_NAME $fastcgi_script_name;
}
location / {
root /srv/mysite/frontend/dist;
try_files $uri /index.html;
}
}

此错误消息显示了sock文件的错误路径或权限。确保php sock文件存在于路径/run/php/php7.2-fpm.sock中,并更改该文件的权限。

For Debian
chown -R  wwww-data:www-data /run/php/php7.2-fpm.sock
For Rhel
chown -R nginx:nginx /run/php/php7.2-fpm.sock

此外,您可以尝试此配置。

location /blog {
root /srv/mysite/wordpress;
}
location ~ .php$ {
try_files $uri /index.php =404;
fastcgi_split_path_info ^(.+.php)(/.+)$;
fastcgi_pass unix:/run/php/php7.2-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;

最新更新