Home > Blockchain >  Docker NGiNX/PHP services not serving PHP
Docker NGiNX/PHP services not serving PHP

Time:02-10

I have set up a docker-compose.yml file to start a NGiNX server and serve PHP content, the thing is it keeps on showing the default NGiNX welcome page when I visit localhost:8080.

Here's my docker-compose.yml

version: "3"
services:
  web: 
    image: nginx:latest
    ports:
      - "8080:80"
    volumes:
      - ./public:/public
      - ./site.conf:/etc/nginx/conf.d/site.conf
    links:
      - php
  php:
    image: php:8-fpm
    volumes:
      - ./public:/public

And here's my site.conf

server {
    index index.php index.html;
    error_log  /var/log/nginx/error.log;
    access_log /var/log/nginx/access.log;
    root /public;

    location ~ \.php$ {
        try_files $uri =404;
        fastcgi_split_path_info ^(. \.php)(/. )$;
        fastcgi_pass php:9000;
        fastcgi_index index.php;
        include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_param PATH_INFO $fastcgi_path_info;
    }
}

CodePudding user response:

If you have an index.php file inside the public folder, you just need to change the docker-compose.yml to:

volumes:
  - ./public:/public
  - ./site.conf:/etc/nginx/conf.d/default.conf
  • Related