Return 404 (Not Found) when trying to access multiple laravel application dockerized

Viewed 22

Im trying to dockerize multiple laravel applications on my local machine

My goal is to access these apps using the local domain (ex: app1.localhost, app2.localhost, etc.) that I defined in my docker-compose.yaml

I'm using the nginxproxy/nginx-proxy image and running it independently.

Here is my configuration.

nginx-proxy > docker-compose.yaml

version: '3.8'

services:
  nginx-proxy:
    image: nginxproxy/nginx-proxy
    container_name: nginx-proxy
    ports:
      - '80:80'
    volumes:
      - /var/run/docker.sock:/tmp/docker.sock:ro

networks:
  default:
    name: local-network

The next thing I do is docker-compose up -d

After making sure this nginx-proxy runs without error, I moved to my laravel applications.

  • App 1

app1 > docker-compose.yaml

version: '3.8'

services:
  server:
    build:
      context: .
      dockerfile: dockerfiles/nginx.dockerfile
    ports:
      - '8001:80'
    volumes:
      - ./src:/var/www/client
      - ./nginx/nginx.conf:/etc/nginx/conf.d/default.conf:ro
    depends_on:
      - php
    environment:
      - VIRTUAL_HOST=app1.localhost
  php:
    build:
      context: .
      dockerfile: dockerfiles/php.dockerfile
    volumes:
      - ./src:/var/www/client:delegated
    ports:
      - '9001:9000'
networks:
  default:
    name: local-network

And continue to build the container for my laravel app1.

Im trying to run it with the local domain (app1.localhost), and it runs well without error.

Then I moved to my App 2 with the same configuration above and some adjustments, which is changing the ports and VIRTUAL_HOST

  • App 2

app2 > docker-compose.yaml

version: '3.8'

services:
  server:
    build:
      context: .
      dockerfile: dockerfiles/nginx.dockerfile
    ports:
      - '8002:80'
    volumes:
      - ./src:/var/www/internal
      - ./nginx/nginx.conf:/etc/nginx/conf.d/default.conf:ro
    depends_on:
      - php
    environment:
      - VIRTUAL_HOST=app2.localhost
  php:
    build:
      context: .
      dockerfile: dockerfiles/php.dockerfile
    volumes:
      - ./src:/var/www/internal:delegated
    ports:
      - '9002:9000'
networks:
  default:
    name: local-network

The build image and container were a success.

Then when I tried to access the local domain (app2.localhost), it returned 404 not found on the screen, and when I checked the container server logs for App 2, it gave the error message below

[error] 22#22: *7 FastCGI sent in stderr: "Primary script unknown" while reading response header from upstream, client: 172.18.0.2, server: localhost, request: "GET / HTTP/1.1", upstream: "fastcgi://172.18.0.3:9000", host: "app2.localhost"
0 Answers
Related