404 in container Docker NGINX

0

Hello developer friends!

I'm having a problem with NGINX where the application root is not found, reminding me that I need a "mod_rewrite" to make my URLs beautiful. I'll leave the NGINX settings and 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
    
asked by anonymous 25.07.2017 / 15:40

1 answer

0

The use of Links is deprecated 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;
    }
}
    
23.01.2018 / 21:06