diff --git a/docker-compose.yml b/docker-compose.yml index df087b6..74dc763 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,17 +1,15 @@ -version: "3.8" - services: - db: - image: mysql:8.0 - container_name: dishplanner-db + web: + image: nginx:alpine + container_name: dishplanner-nginx restart: unless-stopped - environment: - MYSQL_ROOT_PASSWORD: rootpassword - MYSQL_DATABASE: dishplanner - MYSQL_USER: dishuser - MYSQL_PASSWORD: dishpass + depends_on: + - backend volumes: - - db_data:/var/lib/mysql + - ./nginx/nginx.conf:/etc/nginx/conf.d/default.conf:ro + command: /bin/sh -c "until nslookup backend. ; do sleep 2; done && nginx -g 'daemon off;'" + ports: + - "3000:80" backend: image: jochent/dishplanner-backend:latest @@ -27,19 +25,31 @@ services: depends_on: - db ports: - - "9000:9000" # Only needed if exposing php-fpm, otherwise remove + - "8080:8080" frontend: image: jochent/dishplanner-frontend:latest container_name: dishplanner-frontend restart: unless-stopped - environment: - NEXT_PUBLIC_API_URL: http://localhost:9000 # or backend:9000 if hitting directly depends_on: - backend - ports: - - "3000:3000" +# ports: +# - "3000:3000" + db: + image: mysql:8.0 + container_name: dishplanner-db + restart: unless-stopped + environment: + MYSQL_ROOT_PASSWORD: rootpassword + MYSQL_DATABASE: dishplanner + MYSQL_USER: dishuser + MYSQL_PASSWORD: dishpass + volumes: + - db_data:/var/lib/mysql volumes: db_data: +networks: + default: + name: dishplanner-net diff --git a/nginx/default.conf b/nginx/default.conf deleted file mode 100644 index 0947a1f..0000000 --- a/nginx/default.conf +++ /dev/null @@ -1,20 +0,0 @@ -server { - listen 80; - - # Route API requests to Laravel - location /api/ { - proxy_pass http://backend:80/; - proxy_set_header Host $host; - proxy_set_header X-Real-IP $remote_addr; - proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; - } - - # Route all other requests to React - location / { - proxy_pass http://frontend:3000/; - proxy_set_header Host $host; - proxy_set_header X-Real-IP $remote_addr; - proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; - try_files $uri /index.html; - } -} diff --git a/nginx/nginx.conf b/nginx/nginx.conf new file mode 100644 index 0000000..4eb4d39 --- /dev/null +++ b/nginx/nginx.conf @@ -0,0 +1,53 @@ +server { + listen 80; + server_name localhost; + + # === FRONTEND === + location / { + proxy_pass http://frontend:3000; + proxy_http_version 1.1; + + proxy_set_header Host $host; + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + proxy_set_header X-Forwarded-Proto $scheme; + + # WebSocket support (optional but good for Next.js dev tools etc.) + proxy_set_header Upgrade $http_upgrade; + proxy_set_header Connection "upgrade"; + } + + # === BACKEND API === + location /api/ { + proxy_pass http://backend:80; + proxy_http_version 1.1; + + proxy_set_header Host $host; + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + proxy_set_header X-Forwarded-Proto $scheme; + } + + # === Sanctum (Laravel token auth) === + location /sanctum/ { + proxy_pass http://backend:80; + proxy_http_version 1.1; + + proxy_set_header Host $host; + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + proxy_set_header X-Forwarded-Proto $scheme; + } + + # === Client-side routing fallback (Next.js or SPA mode) === + error_page 404 /index.html; + location = /index.html { + proxy_pass http://frontend:3000/index.html; + proxy_http_version 1.1; + + proxy_set_header Host $host; + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + proxy_set_header X-Forwarded-Proto $scheme; + } +}