【问题标题】:Nginx with php7.1-fpm showing blank php pagesNginx 与 php7.1-fpm 显示空白 php 页面
【发布时间】:2018-03-05 20:13:20
【问题描述】:

背景与环境

我正在尝试使用 PHP7.1-FPM 部署 Nginx 服务器,按照说明 herehere

  • 服务器是Ubuntu 16.04
  • Nginx 版本为1.13.3
  • PHP 版本为 PHP 7.1.9-1+ubuntu16.04.1+deb.sury.org+1 (cli) (built: Sep 2 2017 05:56:43) ( NTS )

我对这一切还很陌生,所以与经验丰富的 linux 管理员相比,我仍然对什么是什么一无所知,但我知道足以处理基础知识。

问题

当我浏览到带有 inspired01.DOMAIN.com/application/ 的 URL 时,我得到一个空白页面。 nginx错误日志中没有条目。

当我浏览到诸如 inspired01.DOMAIN.com/application/index.php 之类的 URL 时,我收到 404 错误。

到目前为止尝试过

我已经尝试了 stackoverflow 帖子 here 中的建议。据我所知,我的配置已经包含人们所说的为他们解决了这个问题的建议条目。

我无法通过这些答案解决问题。由于那个帖子已经有几年了,我想也许从那时起要求已经改变了。

我的 Nginx 配置

我的nginx.conf 是:

user inspired786;
worker_processes auto;
pid /run/nginx.pid;
include /etc/nginx/modules-enabled/*.conf;

events {
    worker_connections 1024;
    multi_accept on;
}

http { 
    sendfile on;
    tcp_nopush on;
    tcp_nodelay on;
    keepalive_timeout 25;
    types_hash_max_size 2048;
    server_tokens off;
    client_max_body_size 64m;

    include /etc/nginx/mime.types;
    default_type application/octet-stream;

    ssl_protocols TLSv1 TLSv1.1 TLSv1.2; # Dropping SSLv3, ref: POODLE
    ssl_prefer_server_ciphers on;

    access_log /var/log/nginx/access.log;
    error_log /var/log/nginx/error.log;

    gzip on;
    gzip_disable "msie6";

    gzip_proxied any;
    gzip_comp_level 2;
    gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript;

    # Virtual Host Configs

    include /etc/nginx/conf.d/*.conf;
    include /etc/nginx/sites-enabled/*;

server {
    listen 80 default_server;
    listen [::]:80 default_server;
    server_name _;
    return 444;
    }
}

网站的conf文件是:

server {
    listen 80;
    listen [::]:80;

    server_name inspired01.DOMAIN.com;

    access_log /home/inspired786/DOMAIN.com/logs/access.log;
    error_log /home/inspired786/DOMAIN.com/logs/error.log;

    root /home/inspired786/DOMAIN.com/public/;
    index index.php;

    location / {
        try_files $uri $uri/ /index.php?$args;
    }

    location ~ \.php$ {
        try_files $uri =404;
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_pass unix:/run/php/php7.1-fpm.sock;
        fastcgi_index index.php;
        include fastcgi_params;
    }
}

日志

Nginx 服务器或站点日志中没有生成条目。

/var/log/php7.1-fpm.log 处的 FPM 日志中没有记录相关条目

问题

我想知道这个配置是否有明显的遗漏或错误,这可能会导致php文件不被解析。

更新

根据下面的评论,粘贴在这里,以便任何新人看到它:

我启用了debug_connection 并查看了大量的日志输出 产生的。据我所知,没有问题 报道。好吧,没有明显的errorswarnings。所以我创建了一个 基本的hello.php 文件,包括基本的回显命令,以及 php信息。该文件工作正常。所以我怀疑这个问题是什么 别的。继续调查。

暂时考虑这个问题,而我正在研究空白页问题的其他可能性。

【问题讨论】:

  • 查看 FPM 日志和/或至少查看 nginx 日志
  • 日志中没有相关内容。我已经更新了问题以澄清这一点(关于 Nginx 日志)并添加了关于 FPM 日志的信息。
  • 我启用了debug_connection 并查看了产生的大量日志输出。据我所知,没有报告任何问题。好吧,没有明显的errorswarnings。所以我创建了一个基本的hello.php 文件,包括一个基本的 echo 命令,还有 phpinfo。该文件工作正常。所以我怀疑问题是别的。继续调查。
  • 空白页通常是 PHP 错误。 PHP 错误可以记录到nginx(它曾经是某些平台上的默认设置),但phpinfo 应该会告诉您您的error_log 设置是什么。您可能需要记录 PHP 错误才能解决此问题。

标签: nginx php-7.1


【解决方案1】:

我在 Linux 2.6、PHP5 和 nginx 上运行 我的 PHP 文件显示为文本

经过多次测试,我更改了默认文件 C:\username\etc\nginx\sites-enabled 如下:

location ~ [^/]\.php(/|$) {
  fastcgi_split_path_info ^(.+\.php)(/.+)$;
  include fastcgi_params;
  # NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini
  # With php5-cgi alone:
  fastcgi_pass 127.0.0.1:9000;
  # With php5-fpm:
  #fastcgi_pass unix:/var/run/php5-fpm.sock;
  fastcgi_index index.php;
  fastcgi_param  SCRIPT_FILENAME $document_root$fastcgi_script_name;
}

重启 nginx 和 PHP 服务后 PHP 开始工作了!

检查你的 php 文件是否在默认文件中设置的根路径下 并从 test.php 文件开始测试,如下所示:

<?php
/* test.php */
  phpinfo();
?>

【讨论】:

    【解决方案2】:

    尝试修复项目目录中的权限。在 Linux 中,这对我有用:

    sudo chown -R www-data:www-data .
    

    【讨论】:

      猜你喜欢
      • 2013-03-03
      • 1970-01-01
      • 1970-01-01
      • 2018-07-05
      • 2016-01-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多