0

当我打开我的应用程序时,我试图在 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;
}

先感谢您

4

2 回答 2

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 版本匹配

于 2020-06-05T14:07:03.650 回答
0

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

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

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

于 2020-06-05T14:03:12.610 回答