diff --git a/Dockerfile b/Dockerfile index 208739b..cd67806 100644 --- a/Dockerfile +++ b/Dockerfile @@ -20,9 +20,8 @@ RUN chown -R www-data:www-data /var/www/html WORKDIR /var/www/html -COPY ./docker/supervisord.conf /etc/supervisor/conf.d/supervisord.conf COPY ./docker/entrypoint.sh /entrypoint.sh RUN chmod +x /entrypoint.sh ENTRYPOINT ["/entrypoint.sh"] -CMD ["supervisord", "-n", "-c", "/etc/supervisor/conf.d/supervisord.conf"] \ No newline at end of file +CMD ["docker-php-entrypoint", "php-fpm"] \ No newline at end of file diff --git a/Dockerfile.queue b/Dockerfile.queue new file mode 100644 index 0000000..08526a4 --- /dev/null +++ b/Dockerfile.queue @@ -0,0 +1,16 @@ +FROM php:8.3-fpm + +# 安裝必要套件與 PHP 擴充 +RUN apt-get update && apt-get install -y \ + git unzip zip curl libzip-dev libonig-dev libxml2-dev && \ + docker-php-ext-install pdo_mysql zip bcmath + +COPY ./data/KTVCentral/ /var/www/html/ + +RUN chown -R www-data:www-data /var/www/html + +WORKDIR /var/www/html + +COPY ./docker/supervisord.conf /etc/supervisor/conf.d/supervisord.conf + +CMD ["supervisord", "-n", "-c", "/etc/supervisor/conf.d/supervisord.conf"] \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml index ff86325..31ae94d 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -53,6 +53,16 @@ services: NGINX_PORT: ${APP_PORT} networks: - app_network + queue: + build: + context: . + dockerfile: Dockerfile.queue + volumes: + - ./data/KTVCentral:/var/www/html + depends_on: + - nginx + networks: + - app_network networks: app_network: name: ${APP_NAME}_network diff --git a/docker/entrypoint.sh b/docker/entrypoint.sh index fa8510d..33e330f 100644 --- a/docker/entrypoint.sh +++ b/docker/entrypoint.sh @@ -54,4 +54,8 @@ echo "Installing npm packages..." echo "Building front-end assets..." npm run build +echo "Setting permissions for storage and bootstrap/cache..." +chown -R www-data:www-data /var/www/html/storage /var/www/html/bootstrap/cache +chmod -R 775 /var/www/html/storage /var/www/html/bootstrap/cache + exec "$@" \ No newline at end of file diff --git a/docker/nginx/default.conf.template b/docker/nginx/default.conf.template index 48db178..43e11c0 100644 --- a/docker/nginx/default.conf.template +++ b/docker/nginx/default.conf.template @@ -14,10 +14,20 @@ server { location ~ \.php$ { include fastcgi_params; + fastcgi_pass app:9000; fastcgi_index index.php; - fastcgi_param SCRIPT_FILENAME /var/www/html$fastcgi_script_name; + + # Laravel 正確位置 + fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; + + # Optional: 支援 PATH_INFO fastcgi_param PATH_INFO $fastcgi_path_info; + fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info; + + # 避免 NGINX 直接 cache + fastcgi_buffer_size 16k; + fastcgi_buffers 4 16k; } location ~ /\.ht { diff --git a/docker/supervisord.conf b/docker/supervisord.conf index 081b789..57041c7 100644 --- a/docker/supervisord.conf +++ b/docker/supervisord.conf @@ -3,20 +3,12 @@ nodaemon=true logfile=/var/www/logs/supervisord.log ; 設定 log 儲存位置 pidfile=/var/www/logs/supervisord.pid ; 設定 pid 儲存位置 -[program:php-fpm] -command=docker-php-entrypoint php-fpm -autostart=true -autorestart=true -priority=1 -stdout_logfile=/var/www/logs/php-fpm.log -stderr_logfile=/var/www/logs/php-fpm.err.log - [program:queue-worker] directory=/var/www/html command=php artisan queue:work --daemon --timeout=3600 --tries=1 --queue=default autostart=true autorestart=true -priority=2 +priority=1 stdout_logfile=/var/www/logs/queue.log stderr_logfile=/var/www/logs/queue_error.log @@ -25,6 +17,6 @@ directory=/var/www/html command=sh -c "while true; do php artisan schedule:run; sleep 60; done" autostart=true autorestart=true -priority=3 +priority=2 stdout_logfile=/var/www/logs/schedule.log stderr_logfile=/var/www/logs/schedule_error.log