nginx 工作正常,但 php7.2-fpm 工作不正常

我正在尝试在 ubuntu 18.04 上使用 nginx 运行 php7.2-fpm 来运行 Wordpress。Nginx 工作正常,但 php 无法工作。


日志档案:


2020/08/10 11:06:34 [error] 107906#107906: *1 open() "/usr/share/nginx/htmlunix:/run/php/php7.2-fpm.sock" failed (2: No such file or directory), client: ###.###.###.###, server: example.com, request: "GET /index.php HTTP/1.1", host: "example.com"

2020/08/10 11:09:57 [error] 108481#108481: *1 open() "/usr/share/nginx/html404" failed (2: No such file or directory), client: ###.###.###.###, server: example.com, request: "GET /index.php HTTP/1.1", host: "example.com"

2020/08/10 11:20:13 [error] 109596#109596: *1 open() "/usr/share/nginx/html404" failed (2: No such file or directory), client: ###.###.###.###, server: example.com, request: "GET /index.php HTTP/1.1", host: "example.com"

2020/08/10 11:22:35 [error] 110539#110539: *1 open() "/usr/share/nginx/html404" failed (2: No such file or directory), client: ###.###.###.###, server: example.com, request: "GET /index.php HTTP/1.1", host: "example.com"

2020/08/10 11:22:36 [error] 110539#110539: *2 open() "/usr/share/nginx/html404" failed (2: No such file or directory), client: ###.###.###.###, server: example.com, request: "GET /index.php HTTP/1.1", host: "example.com"

2020/08/10 11:26:10 [error] 110817#110817: *1 open() "/usr/share/nginx/html404" failed (2: No such file or directory), client: ###.###.###.###, server: example.com, request: "GET /index.php HTTP/1.1", host: "example.com"

抱歉我的英语很短。


当年话下
浏览 99回答 1
1回答

慕少森

您的配置文件配置错误nginx。首先,您在节内指定root和index指令location \。location / {        root  /data/web;        index index.html index.htm;}该部分仅在所有其他部分不匹配时才起作用,因为它具有短路掩码长度(/是一个符号)每个URL以.php、 likephpinfo.php或结尾的都index.php将匹配到location ~ \.php$部分:location ~ \.php$ {        try_files            $uri = 404;        fastcgi_pass         unix:/run/php/php7.2-fpm.sock;        fastcgi_index        index.php;        include              fastcgi_params;        fastcgi_read_timeout 300;}但是 - 没有rootandindex指令(顺便说一句,index这是可选的,但在您的情况下,first 是强制性的)。有两种解决方案:首先,在部分中指定root和index指令location ~ \.php$:location ~ \.php$ {        try_files            $uri = 404;        root                 /data/web;        index                index.php index.html index.htm;        fastcgi_pass         unix:/run/php/php7.2-fpm.sock;        fastcgi_param        SCRIPT_FILENAME $document_root/$fastcgi_script_name;        fastcgi_index        index.php;        include              fastcgi_params;        fastcgi_read_timeout 300;}第二个是将rootand放在index全局上下文中(在 内部server):server {    listen 80;    charset UTF-8;    server_name example.com www.example.com;    root  /data/web;    index index.php index.html index.htm;    ...}UPD:还fastcgi_param SCRIPT_FILENAME $document_root/$fastcgi_script_name;必须在之后添加指令fastcgi_pass
打开App,查看更多内容
随时随地看视频慕课网APP