当安装完最新版的nginx和最新版的PHP以后,使用niginx默认配置文件中的PHP配置会有错误
访问指定目录下的php文件时,显示File not found.错误。查看nginx的错误日志显示
90#90: *1 FastCGI sent in stderr: "Primary script unknown" while reading response header from upstream, client: 127.0.0.1, server: 127.0.0.1, request: "GET /index.php HTTP/1.1", upstream: "fastcgi://127.0.0.1:9000", host: "127.0.0.1"
排查的过程:
1.修改默认PHP配置中的fastcgi_param配置fastcgi_param配置,这个地方默认的是/Scripts$fastcgi_script_name
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
2.把root指令从location /{}块里面拿到外面,因为看fpm的access日志,访问PHP文件报的404错误
最简配置如下:
server { listen 80; server_name 127.0.0.1; access_log /var/log/nginx/default.access.log main; error_log /var/log/nginx/default.error.log; root /var/www/html; location / { index index.html index.htm; } location ~ .php$ { fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; } }