I've setup Docker with a custom Nginx/PHP image for my Laravel app. I'm serving it via Traefik as I'm hosting multiple sites on one machine. Nginx only returns the Welcome to Nginx
page when I load up the site. I've verified via nginx -T
that my Nginx config is setup correctly. I've entered the Docker container via terminal and see all my files there. I've narrowed the issue down to Traefik
- if I remove the Traefik tags and expose a port instead, my site shows up just fine. This is true of identically configured sites not using Traefik. I need to be able to use Traefik but have it return my Laravel app (called Laraview) instead found in src
. Thanks for your help! Here is my config:
Dockerfile
FROM justintime50/nginx-php:latest
COPY --chown=www-data:www-data ./src /var/www/html
COPY nginx.conf /etc/nginx/conf.d/default.conf
RUN php composer.phar install -q --no-ansi --no-interaction --no-scripts --no-suggest --no-progress --prefer-dist
RUN chmod -R 775 storage \
&& php artisan storage:link \
&& chmod -R 775 bootstrap/cache
nginx.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 /var/www/html/public;
try_files $uri $uri/ /index.php;
location ~ \.php$ {
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass 127.0.0.1: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
version: "3.7"
services:
laraview:
build: .
restart: always
container_name: laraview
volumes:
# - ./src:/var/www/html # Only use for development
- ./src/.env:/var/www/html/.env
- ./src/storage/logs:/var/www/html/storage/logs
- ./src/storage/app/public:/var/www/html/storage/app/public
networks:
- traefik
- laraview
labels:
- traefik.enabled=true
- traefik.docker.network=traefik
- traefik.frontend.rule=Host:laraview.localhost
- traefik.port=80
env_file:
- init-db.env
depends_on:
- laraview-db
laraview-db:
image: mysql:5.7.26
restart: always
container_name: laraview-db
env_file:
- init-db.env
volumes:
- ./db:/var/lib/mysql
networks:
- laraview
ports:
- "3306:3306"
labels:
- traefik.enable=false
networks:
traefik:
external:
name: traefik
laraview:
name: laraview
traefik.enabled=true
should be
traefik.enable=true
Also
server_name localhost;
doesn't match your hostname in the docker-compose