centos nginx php错误的解决办法:1、分析是否安装了php-fpm,如果没有就安装php-fpm;2、修改nginx.conf文件或者default.conf;3、保存文件并重启nginx即可。

本文操作环境:centOS6.8系统、PHP7.1版,DELL G3电脑
CentOS6.10 Nginx无法解析php文件
nginx 已经安装完毕,并且能够访问
立即学习“PHP免费学习笔记(深入)”;
当访问 .php 文件时会默认下载,或者提示 “File not found.”
PHP 版本: # php -v PHP 5.3.3 (cli) (built: Mar 22 2017 12:27:09) Copyright (c) 1997-2010 The PHP Group Zend Engine v2.3.0, Copyright (c) 1998-2010 Zend Technologies
Nginx 版本:[root@bogon sbin]# ./nginx -v nginx version: nginx/1.11.6
可以运行命令
service php-fpm start,如果显示无法识别,说明没有安装
可以执行安装命令:
yum install php-fpm然后再运行命令service php-fpm start
(1). 修改 nginx.conf 文件或者 default.conf ,如下图所示,修改其中几处信息。如“root”指的是我的 nginx 根目录,可根据自己的情况进行配置


(2). 保存文件,并重启 nginx,命令:service nginx restart (3). 此时,浏览器访问.php文件即可(如果不是本机访问,注意关闭防火墙)
server{
listen 80;
server_name app-hpoption-admin-test.azfaster.com;
root /data/wwwroot/blog/public;
charset utf-8;
location / {
index index.php index.html ;
try_files $uri $uri/ /index.php?$query_string;
}
#location ~ .php$ {
# fastcgi_pass 127.0.0.1:9000;
# fastcgi_index index.php;
# fastcgi_param SCRIPT_FILENAME /var/www/test/public$fastcgi_script_name;
# include fastcgi_params;
#}
location ~ .*\.(php|php5)?$ {
# fastcgi_pass unix:/dev/shm/php-cgi.sock;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /data/wwwroot/blog/public$fastcgi_script_name;
include fastcgi_params;
}
error_page 404 /404.html;
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}推荐学习:《PHP视频教程》
PHP怎么学习?PHP怎么入门?PHP在哪学?PHP怎么学才快?不用担心,这里为大家提供了PHP速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号