解决启动php-fpm后访问不到php文件的办法
问题场景:
- linux系统
- nginx服务器
- 安装好了fpm的php7
- 在nginx的web目录下新建了index.php文件,内容为phpinfo()函数。(如果是源码安装,位置一般为/usr/local/nginx/html/index.php)
nginx经过了简单的配置,开始试验是否可以支持php
location/{
roothtml;
indexindex.htmlindex.htmindex.php;
}
location~\.php${
roothtml;
fastcgi_pass127.0.0.1:9000;
fastcgi_indexindex.php;
fastcgi_paramSCRIPT_FILENAME/scripts$fastcgi_script_name;
includefastcgi_params;
}
在浏览器访问localhost/index.php
结果为Filenotfound.
这时候我们查看nginx的错误日志,错误日志的主要内容为FastCGIsentinstderr:"Primaryscriptunknown"
经过分析+搜索前辈经验得出结论,nginx的配置文件无法识别/scripts路径,所以我们将配置文件中的/scripts改为$document_root,或者web目录的绝对路径。更改后的配置文件如下:
location~\.php${
roothtml;
fastcgi_pass127.0.0.1:9000;
fastcgi_indexindex.php;
fastcgi_paramSCRIPT_FILENAME$document_root$fastcgi_script_name;
includefastcgi_params;
}
重启nginx服务器,已经可以正确显示phpinfo()的内容了。
总结
以上就是这篇文章的全部内容了,希望本文的内容对大家的学习或者工作能带来一定的帮助,如果有疑问大家可以留言交流。
热门推荐
1 训练狗狗憋尿
2 狗狗追踪训练
3 狗狗训练要多少钱
5 深圳狗狗训练
6 训练狗狗唤回
7 狗狗叫怎么训练
8 狗狗训练班
10 狗狗社会化训练
11 狗狗叫回训练
12 广州狗狗训练学校
13 狗狗训练躺下
14 狗狗随行训练
15 训练狗狗巡回
16 狗狗要怎么训练
17 狗狗喂食训练
18 训练狗狗躺下