404 in Docker NGINX container

Asked

Viewed 766 times

0

Hello fellow developers!

I am having a problem with NGINX in which the root of the application is not found, remembering that I need a "mod_rewrite" to make my Urls beautiful. I will leave the NGINX settings and the Docker-Compose.yml. Vlw :metal:

site conf.

server {
    index index.php index.html;
    server_name php-docker.local;
    error_log  /var/log/nginx/error.log;
    access_log /var/log/nginx/access.log;
    root /app/public;

    location ~ \.php$ {
        try_files $uri $uri/ /index.php?$args;
        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;
    }
}

Docker-Compose.yml

version: '3.2'
services:
    nginx:
        image: nginx:latest
        ports:
            - "8000:80"
        volumes:
            - .:/app
            - ./site.conf:/etc/nginx/conf.d/default.conf
        links:
            - php
    php:
        image: php:7-fpm
        volumes:
            - .:/app

1 answer

1

Use of Links is discontinued in Docker.

Docker-Compose.yml

version: '2'

services:
    web:
        image: nginx:latest
        ports:
            - "8000:80"
        volumes:
            - ./app:/app
            - ./site.conf:/etc/nginx/conf.d/default.conf
        networks:
            - rede-app
    php:
        image: php:fpm
        volumes:
            - ./app:/app
        networks:
            - rede-app

networks:
    rede-app:
        driver: bridge

site conf.

server {
    listen 80;
    index index.php index.html;
    server_name localhost;
    error_log  /var/log/nginx/error.log;
    access_log /var/log/nginx/access.log;
    root /app;

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

Browser other questions tagged

You are not signed in. Login or sign up in order to post.