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

2 Answers 2

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

Sign up to request clarification or add additional context in comments.

Comments

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.