0

I'm trying to configure nginx config in Docker but when I start "sudo docker-compose up -d" and try to connect to "http://localhost:8098/" I see: File not found. and logs like:

docker-infrastructure_php-fpm_1 | 172.19.0.3 -  03/Mar/2022:21:35:35 +0000 "GET /index.php" 404
docker-infrastructure_nginx_1 | 172.19.0.1 - - [03/Mar/2022:21:35:35 +0000] "GET / HTTP/1.1" 404 27 "-" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/98.0.4758.102 Safari/537.36" "-"`

There are my: nginx.conf

server {
    listen 80;
    server_name dgtips-backend-local;
    root /home/sergey/PhpstormProjects/dgtips-backend/public;
    index index.php;

    location / {
        try_files $uri /$uri /index.php?$query_string;
    }

    location ~ [^/]\.php(/|$) {

        fastcgi_param SCRIPT_FILENAME /home/sergey/PhpstormProjects/dgtips-backend$fastcgi_script_name;
        fastcgi_pass php-fpm:9000;
        fastcgi_index index.php;
        fastcgi_split_path_info ^(.+\.php)(/.*)$;
        include fastcgi_params;
    }
}

nginx.Dockerfile

FROM nginx

ADD docker/nginx/nginx.conf /etc/nginx/conf.d/default.conf

WORKDIR /home/sergey/PhpstormProjects/dgtips-backend/public

docker-compose.yml

version: "3.3"

services:
    nginx:
        build:
          context: .
          dockerfile: docker/nginx/nginx.Dockerfile
        ports:
            - 8098:80
        volumes:
          - ./:/home/sergey/PhpstormProjects/dgtips-backend
        links:
          - php-fpm
    php-fpm:
        build:
            context: .
            dockerfile: docker/php-fpm/fpm.Dockerfile
        volumes:
          - ./:/home/sergey/PhpstormProjects/dgtips-backend

And finally fpm.Dockerfile

FROM php:7.4-fpm

RUN apt-get update \
&& docker-php-ext-install pdo pdo_mysql

I'm completely sure that I have correct paths to my (local) project and to my index.php file

David Maze
  • 130,717
  • 29
  • 175
  • 215
  • 1
    Silly question but do you have a `public/index.php` file in your project root? – Phil Mar 03 '22 at 23:40
  • I know what the error means but yes, I have publc/index.php ^) –  Mar 04 '22 at 10:55
  • Sorry, didn't mean your question was silly. I should have said _"this might be a silly question but..."_ – Phil Mar 04 '22 at 12:20
  • no problem :) As far as I know, I can get inside the nginx container via ```docker exec -it ... bash```. And I can check if that particular index.php file finds my nginx.conf. Do you know how I can check it? –  Mar 04 '22 at 14:23
  • [Check out this answer](https://stackoverflow.com/a/47296015/283366). You can also make sure you're using the latest build of your images with `docker compose up --build` – Phil Mar 04 '22 at 21:08

0 Answers0