【问题标题】:ZF3 Nginx Serve index.php As Download FileZF3 Nginx 服务 index.php 作为下载文件
【发布时间】:2017-07-26 20:59:33
【问题描述】:

我使用 nginx 和 php 7 安装了 debian 8,用于使用 zendframework 创建端点。当我关注该网站时,我必须将这些添加到我在 nginx 中的虚拟主机配置中。就像我确实看到了下面的代码:

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

    root /var/www/endpoint/html/public;

    server_name my_ip;

    location / {
          index index.php
          try_files $uri $uri/ @php;
    }

location @php {
        # Pass the PHP requests to FastCGI server (php-fpm) on 127.0.0.1:9000
        fastcgi_pass   127.0.0.1:9000;
        fastcgi_param  SCRIPT_FILENAME /var/www/endpoint/html/public/index.php;
        include fastcgi_params;
    }}

但是当我访问该网站时,它会下载 index.php 而不是执行 index.php。

希望有人能帮我解决这个问题。

【问题讨论】:

  • index 内部 location 进行内部重定向。
  • @Deadooshka 你能告诉我我应该如何解决这个问题吗?这是来自原始 github 的信息github.com/zendframework/ZendSkeletonApplication
  • 我不确定你是否需要那个index,因为我看不到正确的location for .php
  • @Deadooshka 不知道。但是当我不使用带有 [at] php 的 zf 配置时,它的工作原理。将其放回下载文件时。
  • 我认为这个配置的逻辑很糟糕,因为如果客户端请求真正的 php 文件,那么它自己会得到一个 php-script。你至少需要默认的 php-handler location \.php$ {}

标签: php linux nginx debian zend-framework3


【解决方案1】:

我认为您需要将 fastcgi_pass 值替换为 socket path 而不是服务器地址和端口。

fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;

然后通过键入此命令重新启动您的php7-fpm

sudo systemctl restart php7-fpm

【讨论】:

    【解决方案2】:

    感谢@Dolly-aswin,

    谢谢,它将 127.0.0.1 替换为 php-fpm sock

    location ~ \.php$ {
                #fastcgi_pass   127.0.0.1:9000;
                fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;
                fastcgi_param  SCRIPT_FILENAME /var/www/endpoint/html/public/index.php;
                include fastcgi_params;
        }
    

    我的 ZendFramework 3 现在正在使用 Nginx (PHP 7) 开发 Debian 8。

    【讨论】:

    • 哦,对不起。我忘了用 PHP7 进行调整。我会编辑我的答案,你能接受吗?
    • @DollyAswin 再次感谢您的大力支持。如果它在一天结束时没有修复,我不得不再次安装 apache:)。
    猜你喜欢
    • 2018-01-28
    • 2014-04-12
    • 1970-01-01
    • 1970-01-01
    • 2021-06-29
    • 1970-01-01
    • 1970-01-01
    • 2021-04-04
    • 1970-01-01
    相关资源
    最近更新 更多