0

I was trying to run the container in Heroku when I open my app it displays the raw file of my 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;
}

Thank you in advance

jemz
  • 4,987
  • 18
  • 62
  • 102

2 Answers2

1

add location:

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;
  }

The fastcgi_pass location must match to your php version

0

I think you must add this code in your location block :

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

Obviously, change the PHP version in my code to match your environment.

lionelp
  • 443
  • 1
  • 7
  • 21