【问题标题】:PHP-FPM/ZF3 download php file when hit root domainPHP-FPM/ZF3 在访问根域时下载 php 文件
【发布时间】:2016-07-30 05:05:57
【问题描述】:

这让我很困惑。当我访问该域时,它会下载index.php 文件。当我访问 domain/index.php 时,它工作正常。我试图在这里和那里发表评论,只是无法修复它。这个是Zend Framework 3。我在同一台服务器上有其他 php 站点。他们很好。我现在开始怀疑它是 ZF3 的特别之处。

我的nginx是这样的:

server {
  listen       80;
  server_name  xxx.xxx.com;
  index index.php index.html;
  root         /data/www/xxx/public;

  location ~ \.php$ {
    fastcgi_pass  127.0.0.1:9000;
    fastcgi_index index.php;
    include       fastcgi_params;
    fastcgi_param  SCRIPT_FILENAME /data/www/xxx/public/index.php; 
  }

  access_log logs/worth.jusfeel.cn.log main;
}

我也尝试过其他设置。一样的。地址栏中的 url 更改为 ..domain/index.php ,但仍然下载 index.php 文件。

server {
  listen      80;
  server_name www.example.com;
  root        /var/www/www.example.com/myapplication;
  index       index.html index.htm index.php;

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

  location ~ \.php$ {
    fastcgi_pass  127.0.0.1:9000;
    fastcgi_param  SCRIPT_FILENAME $document_root$fastcgi_script_name;
    include        fastcgi_params;
  }
}

【问题讨论】:

    标签: php nginx php-7 zf3


    【解决方案1】:

    下载index.php文件意味着nginx不使用php-fpm来处理文件。这种情况最常见的原因是 nginx 和 php-fpm 之间的配置错误。

    清单:

    1. 确保您没有禁用php.ini 中的cgi.fix_pathinfo 指令。它为 CGI 提供真正的PATH_INFO/PATH_TRANSLATED 支持,默认启用(1)
    2. 确保虚拟主机的根目录指向 ZF3 应用程序的 public 目录。在这种情况下,您可能需要将其从 /var/www/www.example.com/myapplication 替换为 /var/www/www.example.com/myapplication/public
    3. 最重要的部分是您需要在location ~ \.php$ { } 块中使用正确的fastcgi_split_path_info 指令,因为所有PHP 请求都通过index.php 处理。该指令定义了一个正则表达式,用于捕获 nginx $fastcgi_path_info 变量的值。

    例如:

    location ~ \.php$ {
      fastcgi_pass            127.0.0.1:9000;
      fastcgi_split_path_info ^(.+.php)(/.+)$;
      fastcgi_param           SCRIPT_FILENAME $document_root$fastcgi_script_name;
      include                 fastcgi_params;
    }
    

    希望对你有帮助。

    【讨论】:

      猜你喜欢
      • 2014-06-16
      • 1970-01-01
      • 2019-08-09
      • 2017-06-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-10-27
      • 2022-11-18
      相关资源
      最近更新 更多