nginx+php报错FileNotFount和403解决

Nginx添加php配置后web页面报错File not found,后台日志显示FastCGI sent in stderr: "Primary script unknown" while reading response header from upstream, 这个需要在Nginx配置里加

root /var/www/html;

目录自己定义,需要写在server块儿里和server_name同级,不能写在location块里, 否则php的 location ~ \.php$ 块无法继承这个设置,导致$document_root 变量在 php location 中为空或错误,fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;$document_root 为空,实际效果相当于尝试访问$fastcgi_script_name ,所以报错。

第二个问题,web页面报错403 forbiden,后台日志显示directory index of "/var/www/html/" is forbidden。这是由于未设置index,server块儿添加

index index.php;

就解决了。

 

阅读剩余
THE END