From 094329369ead9617fb6ccd9fb901adf6fff6cd86 Mon Sep 17 00:00:00 2001 From: z0rayy Date: Wed, 10 Jun 2026 17:26:17 +0700 Subject: [PATCH] Fix Bad Gateway: Replace supervisor with entrypoint.sh, fix nginx.conf --- Dockerfile | 32 ++++++++++++++++++-------------- entrypoint.sh | 11 +++++++++++ nginx.conf | 10 ++++++---- 3 files changed, 35 insertions(+), 18 deletions(-) create mode 100644 entrypoint.sh diff --git a/Dockerfile b/Dockerfile index 0c89b10..cfecd5a 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,27 +1,31 @@ # ========================================================= # Dockerfile - WebGIS PHP Application -# Uses Nginx + PHP-FPM in a single Alpine-based container +# Nginx + PHP-FPM on Alpine (managed by entrypoint shell script) # ========================================================= FROM php:8.2-fpm-alpine -# Install system dependencies and PHP extensions -RUN apk add --no-cache \ - nginx \ - supervisor \ +# Install Nginx and required PHP extensions +RUN apk add --no-cache nginx \ && docker-php-ext-install mysqli pdo pdo_mysql \ && docker-php-ext-enable mysqli pdo_mysql +# CRITICAL: Allow ENV vars from Coolify (DB_HOST, DB_PASS, etc.) +# to be readable via getenv() in PHP. PHP-FPM strips env vars by default. +RUN echo "" >> /usr/local/etc/php-fpm.d/www.conf \ + && echo "[www]" >> /usr/local/etc/php-fpm.d/www.conf \ + && echo "clear_env = no" >> /usr/local/etc/php-fpm.d/www.conf + # Copy Nginx configuration COPY nginx.conf /etc/nginx/nginx.conf -# Copy supervisor configuration (runs Nginx + PHP-FPM together) -COPY supervisord.conf /etc/supervisor/conf.d/supervisord.conf +# Create nginx runtime directories +RUN mkdir -p /run/nginx && \ + mkdir -p /var/log/nginx -# CRITICAL: Allow ENV vars (DB_HOST, DB_PASS etc) from Coolify to be -# readable by PHP's getenv(). By default PHP-FPM clears all env vars. -RUN echo "[www]" >> /usr/local/etc/php-fpm.d/www.conf && \ - echo "clear_env = no" >> /usr/local/etc/php-fpm.d/www.conf +# Copy entrypoint script and make executable +COPY entrypoint.sh /entrypoint.sh +RUN chmod +x /entrypoint.sh # Set working directory WORKDIR /var/www/html @@ -29,12 +33,12 @@ WORKDIR /var/www/html # Copy all application files COPY . . -# Set correct permissions for web files +# Set correct permissions RUN chown -R www-data:www-data /var/www/html \ && chmod -R 755 /var/www/html # Expose port 80 EXPOSE 80 -# Start supervisor (which manages both Nginx and PHP-FPM) -CMD ["/usr/bin/supervisord", "-c", "/etc/supervisor/conf.d/supervisord.conf"] +# Run entrypoint script +CMD ["/entrypoint.sh"] diff --git a/entrypoint.sh b/entrypoint.sh new file mode 100644 index 0000000..f80f8c8 --- /dev/null +++ b/entrypoint.sh @@ -0,0 +1,11 @@ +#!/bin/sh +set -e + +echo "==> Starting PHP-FPM..." +php-fpm -D + +echo "==> Waiting for PHP-FPM to be ready..." +sleep 1 + +echo "==> Starting Nginx..." +exec nginx -g "daemon off;" diff --git a/nginx.conf b/nginx.conf index 6934c72..d049569 100644 --- a/nginx.conf +++ b/nginx.conf @@ -1,6 +1,5 @@ worker_processes auto; error_log /var/log/nginx/error.log warn; -pid /var/run/nginx.pid; events { worker_connections 1024; @@ -23,18 +22,21 @@ http { try_files $uri $uri/ /index.php?$query_string; } - # PHP-FPM handler - all .php files are processed by PHP-FPM + # PHP-FPM: forward all .php requests to PHP-FPM on port 9000 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; + fastcgi_read_timeout 300; } - # Allow access to static files (HTML, CSS, JS, images) + # Cache static files location ~* \.(html|css|js|jpg|jpeg|png|gif|ico|svg|woff|woff2|ttf|eot)$ { - expires max; + expires 1d; access_log off; }