【问题标题】:Nginx did not execute php file but it render the raw textNginx 没有执行 php 文件,但它呈现原始文本
【发布时间】:2020-06-05 13:54:47
【问题描述】:

当我打开我的应用程序时,我试图在 Heroku 中运行容器,它会显示我的 PHP 的原始文件

FROM  ubuntu:latest

ENV PORT=80

[....]

COPY default.conf.template /etc/nginx/conf.d/default.conf.template
COPY nginx.conf /etc/nginx/nginx.conf

 CMD /bin/bash -c "envsubst '\$PORT' < /etc/nginx/conf.d/default.conf.template > /etc/nginx/conf.d/default.conf" && nginx -g 'daemon off;'

default.conf.template

server {
  listen $PORT default_server;
    root   /var/www/myapp;
    index  index.php;

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

nginx.conf

worker_processes 4; # Heroku dynos have at least four cores.

error_log stderr;
pid /var/run/nginx.pid;

events {
  worker_connections 1024;
}

http {
  access_log /dev/stdout;
  server_tokens off; # Hide nginx version in Server header & page footers

  include /etc/nginx/conf.d/*.conf;
}

提前谢谢你

【问题讨论】:

    标签: nginx heroku dockerfile heroku-ci


    【解决方案1】:

    添加位置:

    location ~* \.php$ {
        fastcgi_pass unix:/run/php/php7.0-fpm.sock;
        include         fastcgi_params;
        fastcgi_param   SCRIPT_FILENAME    $document_root$fastcgi_script_name;
        fastcgi_param   SCRIPT_NAME        $fastcgi_script_name;
      }
    

    fastcgi_pass 位置必须与您的 php 版本匹配

    【讨论】:

      【解决方案2】:

      我认为您必须将此代码添加到您的 location 块中:

      include snippets/fastcgi-php.conf;
      fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;
      

      显然,更改我代码中的 PHP 版本以匹配您的环境。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2011-01-21
        • 2017-06-16
        相关资源
        最近更新 更多