Fix Bad Gateway: Replace supervisor with entrypoint.sh, fix nginx.conf
This commit is contained in:
+18
-14
@@ -1,27 +1,31 @@
|
|||||||
# =========================================================
|
# =========================================================
|
||||||
# Dockerfile - WebGIS PHP Application
|
# 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
|
FROM php:8.2-fpm-alpine
|
||||||
|
|
||||||
# Install system dependencies and PHP extensions
|
# Install Nginx and required PHP extensions
|
||||||
RUN apk add --no-cache \
|
RUN apk add --no-cache nginx \
|
||||||
nginx \
|
|
||||||
supervisor \
|
|
||||||
&& docker-php-ext-install mysqli pdo pdo_mysql \
|
&& docker-php-ext-install mysqli pdo pdo_mysql \
|
||||||
&& docker-php-ext-enable mysqli 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 configuration
|
||||||
COPY nginx.conf /etc/nginx/nginx.conf
|
COPY nginx.conf /etc/nginx/nginx.conf
|
||||||
|
|
||||||
# Copy supervisor configuration (runs Nginx + PHP-FPM together)
|
# Create nginx runtime directories
|
||||||
COPY supervisord.conf /etc/supervisor/conf.d/supervisord.conf
|
RUN mkdir -p /run/nginx && \
|
||||||
|
mkdir -p /var/log/nginx
|
||||||
|
|
||||||
# CRITICAL: Allow ENV vars (DB_HOST, DB_PASS etc) from Coolify to be
|
# Copy entrypoint script and make executable
|
||||||
# readable by PHP's getenv(). By default PHP-FPM clears all env vars.
|
COPY entrypoint.sh /entrypoint.sh
|
||||||
RUN echo "[www]" >> /usr/local/etc/php-fpm.d/www.conf && \
|
RUN chmod +x /entrypoint.sh
|
||||||
echo "clear_env = no" >> /usr/local/etc/php-fpm.d/www.conf
|
|
||||||
|
|
||||||
# Set working directory
|
# Set working directory
|
||||||
WORKDIR /var/www/html
|
WORKDIR /var/www/html
|
||||||
@@ -29,12 +33,12 @@ WORKDIR /var/www/html
|
|||||||
# Copy all application files
|
# Copy all application files
|
||||||
COPY . .
|
COPY . .
|
||||||
|
|
||||||
# Set correct permissions for web files
|
# Set correct permissions
|
||||||
RUN chown -R www-data:www-data /var/www/html \
|
RUN chown -R www-data:www-data /var/www/html \
|
||||||
&& chmod -R 755 /var/www/html
|
&& chmod -R 755 /var/www/html
|
||||||
|
|
||||||
# Expose port 80
|
# Expose port 80
|
||||||
EXPOSE 80
|
EXPOSE 80
|
||||||
|
|
||||||
# Start supervisor (which manages both Nginx and PHP-FPM)
|
# Run entrypoint script
|
||||||
CMD ["/usr/bin/supervisord", "-c", "/etc/supervisor/conf.d/supervisord.conf"]
|
CMD ["/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;"
|
||||||
+6
-4
@@ -1,6 +1,5 @@
|
|||||||
worker_processes auto;
|
worker_processes auto;
|
||||||
error_log /var/log/nginx/error.log warn;
|
error_log /var/log/nginx/error.log warn;
|
||||||
pid /var/run/nginx.pid;
|
|
||||||
|
|
||||||
events {
|
events {
|
||||||
worker_connections 1024;
|
worker_connections 1024;
|
||||||
@@ -23,18 +22,21 @@ http {
|
|||||||
try_files $uri $uri/ /index.php?$query_string;
|
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$ {
|
location ~ \.php$ {
|
||||||
|
try_files $uri =404;
|
||||||
|
fastcgi_split_path_info ^(.+\.php)(/.+)$;
|
||||||
fastcgi_pass 127.0.0.1:9000;
|
fastcgi_pass 127.0.0.1:9000;
|
||||||
fastcgi_index index.php;
|
fastcgi_index index.php;
|
||||||
include fastcgi_params;
|
include fastcgi_params;
|
||||||
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
|
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
|
||||||
fastcgi_param PATH_INFO $fastcgi_path_info;
|
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)$ {
|
location ~* \.(html|css|js|jpg|jpeg|png|gif|ico|svg|woff|woff2|ttf|eot)$ {
|
||||||
expires max;
|
expires 1d;
|
||||||
access_log off;
|
access_log off;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user