亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

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

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

PHP
當年話下 2023-09-22 16:38:17
我正在嘗試在 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"抱歉我的英語很短。
查看完整描述

1 回答

?
慕少森

TA貢獻2019條經驗 獲得超9個贊

您的配置文件配置錯誤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


查看完整回答
反對 回復 2023-09-22
  • 1 回答
  • 0 關注
  • 126 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號