seems like you're on the right track, but there are a few areas you might want to double-check. First, ensure that your Nginx configuration is correctly pointing to the /var/www/public directory, as this is where Laravel expects the entry point to be. Double-check that your nginx.dev.conf file reflects this. Also, ensure that the nginx-dev container has access to the correct volumes and paths. The 404 errors could be due to Nginx not properly routing requests to the PHP container. Ensure that your fastcgi_pass directive in Nginx is pointing to the correct app service and port (app:9000). Additionally, verify that your Laravel routes are set up correctly and that there aren’t any typos or missing configurations. Lastly, check the logs of each container (docker-compose logs <service-name>) for any subtle errors that might not be immediately apparent. These logs can give you more context on where things might be going wrong.
Laravel, InertiaJS, Vue3, Docker Compose, Nginx setup struggles
Hello,
I'm at my wits end here and would appreciate any sort of feedback or ideas, think I've looked at every single "guide" on this topic with no success, seems like everyone does it a different way..
I wish to dockerize my webapp with Docker and Docker Compose. I'm using Laravel, InertiaJS, Vue3, Laravel Reverb, and PostgreSQL.
Before attempting to dockerize the solution I used Laravel Herd + pnpm run dev for vite hot reloading, I now wish to use bun and container nginx instead. I have tried to set it up with a dev profile for local dev and a prod profile for prod, getting dev to work is the main point right now.
I get no apparent errors except on Laravel Reverb and 404 not found in Laravel font on localhost:8080
the routes are generated properly for localhost:8080, including a subdomain I have.
the db seems correct and migrations run through, the www archive is properly copied to, php fpm is ran and ready to handle connections, vite server launches at APP_URL, localhost:8080
My leading theory is the directory structure is broken somehow since I constantly get 404 not found but I cannot see how, or maybe the ports?
services:
db:
container_name: db
env_file:
- .env.${COMPOSE_PROFILES:-dev}
image: postgres:15-alpine
environment:
LANG: en_GB UTF-8
POSTGRES_INITDB_ARGS: "--encoding=UTF8 --locale=en_GB.UTF-8"
volumes:
- postgres_data:/var/lib/postgresql/data
command: postgres -c fsync=off
profiles: [dev, prod]
networks:
- default
pgAdmin:
container_name: pgAdmin
image: dpage/pgadmin4
ports:
- "5050:80"
environment:
PGADMIN_DEFAULT_EMAIL: email
PGADMIN_DEFAULT_PASSWORD: password
depends_on:
- db
volumes:
- pgadmin_data:/var/lib/pgadmin
networks:
- default
app:
container_name: app
env_file:
- .env.${COMPOSE_PROFILES:-dev}
build:
context: .
dockerfile: Dockerfile
image: username/grindvakt:${COMPOSE_PROFILES:-dev}
volumes:
- .:/var/www
ports:
- "9000:9000"
working_dir: /var/www
environment:
- APP_ENV=${APP_ENV:-local}
- DB_HOST=db
depends_on:
- db
networks:
- default
profiles: [dev, prod]
bun:
container_name: bun
env_file:
- .env.dev
profiles: [dev]
image: oven/bun:latest
working_dir: /var/www
command: bun run dev
volumes:
- .:/var/www
ports:
- "3000:80"
reverb:
env_file:
- .env.${COMPOSE_PROFILES:-dev}
container_name: reverb
image: php:8.2-cli
command: php /var/www/artisan reverb:start
volumes:
- ./:/var/www
depends_on:
- db
networks:
- default
nginx-dev:
container_name: nginx-dev
restart: unless-stopped
env_file:
- .env.dev
image: nginx:alpine
volumes:
- ./:/var/www
- ./nginx.dev.conf:/etc/nginx/conf.d/default.conf
ports:
- "8080:80"
depends_on:
- app
networks:
- default
nginx-prod:
container_name: nginx-prod
env_file:
- .env.prod
profiles: [prod]
image: nginx:alpine
volumes:
- .:/var/www/html:ro
- ./nginx.prod.conf:/etc/nginx/conf.d/default.conf
ports:
- "443:443"
depends_on:
- app
networks:
default:
name: app-network
volumes:
postgres_data:
pgadmin_data:
FROM php:8.3-fpm-alpine
# Install dependencies
RUN apk add --no-cache postgresql-dev libzip-dev \
zip \
unzip \
curl \
bash \
&& docker-php-ext-install pdo pdo_pgsql zip
# Set working directory
WORKDIR /var/www
# Copy existing application directory contents
COPY . /var/www
# Copy existing application directory permissions
COPY --chown=www-data:www-data . /var/www
# Install composer
COPY --from=composer/composer:latest-bin /composer /usr/bin/composer
# Expose port 9000 and start php-fpm server
EXPOSE 9000
CMD ["php-fpm"]
server {
listen 80;
server_name localhost;
root /var/www/public;
add_header X-Frame-Options "SAMEORIGIN";
add_header X-Content-Type-Options "nosniff";
index index.php index.html index.htm;
charset utf-8;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
location = /favicon.ico { access_log off; log_not_found off; }
location = /robots.txt { access_log off; log_not_found off; }
error_page 404 /index.php;
location ~ \.php$ {
fastcgi_pass app:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
include fastcgi_params;
}
location ~ /\.(?!well-known).* {
deny all;
}
}
After continuing to error search, it all came down to APP_DOMAIN=localhost:8000, apparently declaring the port there is a big no no as changing it fixed everything.
Please or to participate in this conversation.