2

I'm learning Docker and my goal is to set up a Laravel application running on Nginx.

I managed to get to the initial login page, but when I enter credentials and try to login it redirects to the same initial page.

My guess is that is something wrong with the Nginx default.conf file. I tried a lot of things, it must be something simple that I'm missing, it's really frustrating.

Below are some info related to my problem. If there's any other info that I should provide, please let me know.

My folder structure is organized like this:

(It doesn't show all the files inside the src folder, but that's where I cloned the Laravel application)

.
├── docker-compose.yml
├── Dockerfile
├── nginx/
│   └── default.conf
└── src/
    ├── app/
    ├── bootstrap/
    ├── config/
    ├── database/
    ├── public/
    ...
    ├── .env
    ├── composer.json
    ...

Here's my docker-compose.yml:

version: '3'

networks:
  laravel:

services:
  nginx:
    image: nginx:stable-alpine
    container_name: nginx
    ports:
      - "8088:80"
    volumes:
      - ./src:/var/www/html
      - ./nginx/default.conf:/etc/nginx/conf.d/default.conf
    depends_on:
      - php
      - mysql
    networks:
      - laravel

  mysql:
    image: mysql:8.0
    container_name: mysql
    restart: unless-stopped
    tty: true
    ports:
      - "4306:3306"
    environment:
      MYSQL_DATABASE: temp
      MYSQL_USER: temp
      MYSQL_PASSWORD: secret
      MYSQL_ROOT_PASSWORD: secret
      SERVICE_TAGS: dev
      SERVICE_NAME: mysql
    networks:
      - laravel

  php:
    build:
      context: .
      dockerfile: Dockerfile
    container_name: php
    volumes:
      - ./src:/var/www/html
    ports:
      - "9000:9000"
    networks:
      - laravel

  composer:
    image: composer:latest
    container_name: composer
    volumes:
      - ./src:/var/www/html
    working_dir: /var/www/html
    depends_on:
      - php
    networks:
      - laravel

  npm:
    image: node:13.7
    container_name: npm
    volumes:
      - ./src:/var/www/html
    working_dir: /var/www/html
    entrypoint: ['npm']

  artisan:
    build:
      context: .
      dockerfile: Dockerfile
    container_name: artisan
    volumes:
      - ./src:/var/www/html
    depends_on:
      - mysql
    working_dir: /var/www/html
    entrypoint: ['php', '/var/www/html/artisan']
    networks:
      - laravel

Here's the Dockerfile:

FROM php:7.4-fpm-alpine

WORKDIR /var/www/html

RUN docker-php-ext-install pdo pdo_mysql

And here's the default.conf file:

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 /var/www/html/public;

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

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

Thank you for your time.

3
  • Did you ever get an answer for this? Commented Aug 11, 2021 at 3:15
  • Still waiting on an answer to this question. Facing the same issue. On my end I have to always put the application down and up again for it to work. But it gets fraustrating if you have more than one application Commented Oct 10, 2021 at 8:02
  • Same problem in 2022. Commented Oct 25, 2022 at 7:55

1 Answer 1

1

I can't tell exactly what the Issue is, but from my limited view. Check the loginController.php for what the $redirectTo is set equal to. That needs to point to the page you want to go to after login. If you can provide more information that would be helpful.

Sign up to request clarification or add additional context in comments.

2 Comments

Thank you Alex. The request doesn't even arrive at the loginController.php. This same Laravel application works outside docker on Apache.
what is in your config file on the nginx server /sites-available/YOUR-SITE?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.