nginx lemp stack generating 404 error - Docker Compose

Hi all,

I’m new to Docker Compose and running into an issue with Docker and nginx, where every request to my server is generating a 404 error with a “File not found” message.

This is my docker compose file:

services:
   nginx:
     build: ./nginx_docker/
     ports:
       - 80:80
       - 443:443
     volumes:
       - ./www/:/var/www/html/
       - ./nginx_docker/default.conf:/etc/nginx/conf.d/default.conf

   php:
     build: ./php_docker/
     expose:
       - 9000
     volumes:
       - ./www/:/var/www/html/
   db:
     image: mariadb
     volumes:
       -    mysql-data:/var/lib/mysql
     environment:
       -    MYSQL_DATABASE=local_db
       -    MYSQL_ROOT_PASSWORD=test
volumes:
   mysql-data:

nginx Dockerfile:

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

php Dockerfile:

FROM php:8.2-fpm
RUN apt-get update && \
    apt-get install -y libfreetype6-dev libjpeg62-turbo-dev libpng-dev && \
    docker-php-ext-configure gd && \
    docker-php-ext-install gd
RUN docker-php-ext-install mysqli pdo pdo_mysql
RUN docker-php-ext-enable mysqli

Any help with the config would be appreciated!

Have you tried without the custom nginx config? If it works with the default and an HTML, then it is an nginx configuration issue rather than Docker. Except if you refer to the php container incorrectly. But the file that would help to help is the nginx config which is not shared.

What gives you the 404? Is it the PHP application. or nginx?

Thanks! I had followed a tutorial that seems like it had some outdated info / not necessarily the correct way of doing things.

Is this what you mean by removing the custom config? I’ve updated my docker-compose file to be

image: nginx:latest

Instead of the build: line.

I’m now able to see the default nginx page, although I need to configure the file location I think and make sure it’s working with PHP.

No, I meant that you mounted the default config into the container. Did you also remove that? Using the original image without building one with a custom config was necessary, I it would not make a difference without removing the mount line.

1 Like

Thanks! I removed the custom config, and managed to get things working again. Not sure exactly which line was the issue, but after redoing the tutorial I have nginx up and running.

My current issue is that I can’t get nginx to find/see a new MariaDB database created, but will try some more troubleshooting for that.