技术解析

nginx 无法正确解析 php 文件
0
2021-05-25 13:12:09
idczone

1.打开文件后,显示一个可下载的 php 文件,无法看到网页 2.如果打开一个错误的位置,可以显示 nginx 的 404 页面 3.已安装 php 及 php-fpm 4.运行 php 目录中 /bin/国外服务器php 来解析 php 文件可以成功显示


指明 fastcgi 与 nginx 交互的地址了吗 比如 php-fpm 的话应该是本地 9000 端口
fastcgi_pass 127.0.0.1:9000;

1 nginx 根本就不解析 php 文件,所以会提供下载
2
3 参见楼上
4 不能说明任何问题

贴个配置文件参考一下,不知道能不能帮到你~~
server {
listen 80;
server_name 192.168.0.128;
root /var/www/html;
index index.php index.html index.htm index.nginx-debian.html;
location / {
try_files $uri $uri/ =404;
}
error_page 404 /404.html;
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /var/www/html;
}
location ~ \.php$ {
try_files $uri =404;
fastcgi_pass unix:/run/php/php7.0-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}

nginx 不解析 php 文件, php-fpm 才解析,你这种情况是 nginx 运行正常,但是 php 文件没有使用 php-fpm 处理,在 nginx 配置块增加 php 处理模块

感谢三楼

后来按照
"fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;"
重写了 php 部分参数
然后将
"root /var/www/html; "
从 location 中提出到了 server 下就可以正常访问了

这种情况就是 nginx.conf
server 里的 fastcgi 没有配置好。

数据地带为您的网站提供全球顶级IDC资源
在线咨询
专属客服