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
- 1 回答
- 0 關注
- 126 瀏覽
添加回答
舉報