1. Anuncie Aqui ! Entre em contato fdantas@4each.com.br

Docker + Nginx + Laravel = File not found

Discussão em 'Outras Linguagens' iniciado por Rollin, Outubro 9, 2024 às 07:52.

  1. Rollin

    Rollin Guest

    I can't find the reason why my page can't find any PHP file, it shows "file not found" when I visit the page http://dev.mywebsite:8080. I have production and staging containers running on server, production works fine, I have issues only with everything what is prefixed with dev. This is my setup, nginx.conf file:

    server {
    listen 443 ssl http2 default_server;
    listen [::]:443 ssl http2 default_server;

    server_name app.mywebsite.com www.app.mywebsite.com;

    ssl_certificate /etc/nginx/ssl/live/app.roomradius.com/fullchain.pem;
    ssl_certificate_key /etc/nginx/ssl/live/app.roomradius.com/privkey.pem;

    root /var/www/public;
    index index.php index.html;

    if ($host ~* ^www\.(.*)) {
    set $host_without_www $1;
    rewrite ^/(.*)$ $scheme://$host_without_www/$1 permanent;
    }

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


    location /.well-known/acme-challenge/ {
    root /var/www/certbot;
    }


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

    location ~ /\.ht {
    deny all;
    }
    }

    server {
    listen 8080 default_server;
    listen [::]:8080 default_server;
    root /var/dev_www/public;
    index index.php index.html;

    server_name dev.mywebsite.com www.dev.mywebsite.com;

    if ($host ~* ^www\.(.*)) {
    set $host_without_www $1;
    rewrite ^/(.*)$ $scheme://$host_without_www/$1 permanent;
    }

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

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

    location ~ /\.ht {
    deny all;
    }
    }


    This is my production docker-compose:

    services:
    app:
    image: myimage/image_laravel:latest
    container_name: nebo_laravel
    restart: unless-stopped
    tty: true
    environment:
    SERVICE_NAME: app
    SERVICE_TAGS: prod
    APP_NAME: ${APP_NAME}
    APP_URL: ${APP_URL}
    DB_DATABASE: ${DB_DATABASE}
    DB_CONNECTION: ${DB_CONNECTION}
    DB_HOST: ${DB_HOST}
    DB_PORT: ${DB_PORT}
    DB_USERNAME: ${DB_USERNAME}
    DB_PASSWORD: ${DB_PASSWORD}
    APP_ENV: ${APP_ENV}
    APP_KEY: ${APP_KEY}
    APP_DEBUG: ${APP_DEBUG}
    SESSION_DRIVER: ${SESSION_DRIVER}
    QUEUE_CONNECTION: ${QUEUE_CONNECTION}
    volumes:
    - app_data:/var/www
    - app_storage:/var/www/storage
    ports:
    - "9000:9000"
    depends_on:
    - db
    networks:
    - app-network

    certbot:
    image: certbot/certbot
    container_name: certbot
    volumes:
    - ./certbot/www/:/var/www/certbot/:rw
    - ./certbot/conf/:/etc/letsencrypt/:rw
    networks:
    - app-network

    db:
    image: mysql:8.0
    container_name: nebo_db
    restart: unless-stopped
    tty: true
    environment:
    MYSQL_DATABASE: ${DB_DATABASE}
    MYSQL_ROOT_PASSWORD: ${DB_PASSWORD}
    MYSQL_PASSWORD: ${DB_PASSWORD}
    MYSQL_USER: ${DB_USERNAME}
    volumes:
    - dbdata:/var/lib/mysql
    networks:
    - app-network

    networks:
    app-network:
    driver: bridge

    volumes:
    dbdata:
    driver: local
    app_data:
    driver: local
    app_storage:
    driver: local


    My dev (staging) docker-compose:

    services:
    app:
    image: myimagedev/myimage:latest
    container_name: dev_nebo_laravel
    restart: unless-stopped
    tty: true
    environment:
    SERVICE_NAME: app
    SERVICE_TAGS: prod
    APP_NAME: ${APP_NAME}
    APP_URL: ${APP_URL}
    DB_DATABASE: ${DB_DATABASE}
    DB_CONNECTION: ${DB_CONNECTION}
    DB_HOST: ${DB_HOST}
    DB_PORT: ${DB_PORT}
    DB_USERNAME: ${DB_USERNAME}
    DB_PASSWORD: ${DB_PASSWORD}
    APP_ENV: ${APP_ENV}
    APP_KEY: ${APP_KEY}
    APP_DEBUG: ${APP_DEBUG}
    SESSION_DRIVER: ${SESSION_DRIVER}
    QUEUE_CONNECTION: ${QUEUE_CONNECTION}
    volumes:
    - dev_app_data:/var/www
    - dev_app_storage:/var/www/storage
    ports:
    - "9001:9000"
    depends_on:
    - db
    networks:
    - app-network

    certbot:
    image: certbot/certbot
    container_name: dev_certbot
    volumes:
    - ./certbot/dev_www/:/var/www/certbot/:rw
    - ./certbot/dev_conf/:/etc/letsencrypt/:rw
    networks:
    - app-network

    db:
    image: mysql:8.0
    container_name: dev_nebo_db
    restart: unless-stopped
    tty: true
    environment:
    MYSQL_DATABASE: ${DB_DATABASE}
    MYSQL_ROOT_PASSWORD: ${DB_PASSWORD}
    MYSQL_PASSWORD: ${DB_PASSWORD}
    MYSQL_USER: ${DB_USERNAME}
    volumes:
    - dev_dbdata:/var/lib/mysql
    ports:
    - "3307:3307"
    networks:
    - app-network

    networks:
    app-network:
    driver: bridge

    volumes:
    dev_dbdata:
    driver: local
    dev_app_data:
    driver: local
    dev_app_storage:
    driver: local


    This is my nginx docker compose:

    services:
    webserver:
    image: nginx:alpine
    container_name: nebo_webserver
    restart: unless-stopped
    tty: true
    ports:
    - "80:80"
    - "443:443"
    - "8080:8080"
    volumes:
    # Production volumes
    - deploy_prod_app_storage:/var/www/storage
    - deploy_prod_app_data:/var/www
    # Development volumes
    - deploy_dev_dev_app_storage:/var/dev_www/storage
    - deploy_dev_dev_app_data:/var/dev_www
    # Nginx configuration
    - /etc/nginx/conf.d/:/etc/nginx/conf.d/
    # Certbot mappings for production
    - ../deploy_prod/certbot/www:/var/www/certbot/:ro
    - ../deploy_prod/certbot/conf/:/etc/nginx/ssl/:ro
    # Certbot mappings for development
    - ../deploy_dev/certbot/dev_www:/var/www/certbot_dev/:rw
    - ../deploy_dev/certbot/dev_conf:/etc/nginx/ssl_dev/:rw
    # Pass
    - /etc/nginx/.htpasswd:/etc/nginx/.htpasswd
    networks:
    - deploy_prod_app-network
    - deploy_dev_app-network

    networks:
    deploy_prod_app-network:
    external: true
    deploy_dev_app-network:
    external: true

    volumes:
    deploy_prod_app_data:
    external: true
    deploy_prod_app_storage:
    external: true
    deploy_dev_dev_app_data:
    external: true
    deploy_dev_dev_app_storage:
    external: true


    The Laravel app is running, files are inside nginx dev_www folder, when I add there test.html and visit http://dev.mywebsite.com/test.html it shows that file, but when I try to add any PHP file or hit index.php I get "file not found".

    What I am missing here?

    Continue reading...

Compartilhe esta Página