From 4fdcb45a314f97e5212de2d538d7a5a6ef078cd6 Mon Sep 17 00:00:00 2001 From: Muneer shafi Date: Sat, 4 Jan 2025 20:29:48 +0530 Subject: [PATCH] chore: Update Dockerfile-nginx and Dockerfile-php for improved configuration --- docker-compose.yaml | 5 ++--- docker/Dockerfile-nginx | 13 ++++++++++++- docker/build/default.conf | 31 +++++++++++++++---------------- 3 files changed, 29 insertions(+), 20 deletions(-) diff --git a/docker-compose.yaml b/docker-compose.yaml index 2819daa..8d1bef8 100755 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -1,4 +1,5 @@ version: "3.7" + services: fpm: container_name: demo_php @@ -7,11 +8,10 @@ services: dockerfile: ./docker/Dockerfile-php extra_hosts: - "host.docker.internal:host-gateway" - volumes: - ./:/var/www/demo/:cached environment: - # Enhanced Xdebug configuration + # Enhanced Xdebug configuration (optional, only if using Xdebug) PHP_IDE_CONFIG: "serverName=symfony-docker" XDEBUG_MODE: "debug" XDEBUG_SESSION_START: 1 @@ -21,7 +21,6 @@ services: start_with_request=yes log_level=7 log=/tmp/xdebug.log - # Ensure these ports are exposed for Xdebug expose: - 9003 networks: diff --git a/docker/Dockerfile-nginx b/docker/Dockerfile-nginx index 2127d7f..c6e9e74 100755 --- a/docker/Dockerfile-nginx +++ b/docker/Dockerfile-nginx @@ -1,5 +1,16 @@ -FROM nginx +FROM nginx:latest + +# Install necessary utilities to use usermod +RUN apt-get update && apt-get install -y passwd + +# Copy your custom Nginx configuration COPY ./docker/build/default.conf /etc/nginx/conf.d/ +# Create the upstream config RUN echo "upstream php-upstream { server fpm:9000; }" > /etc/nginx/conf.d/upstream.conf + +# Change the user ID for the www-data user (optional) RUN usermod -u 1000 www-data + +# Expose the port the container will listen on +EXPOSE 80 diff --git a/docker/build/default.conf b/docker/build/default.conf index 5ee3a32..1cdd42b 100755 --- a/docker/build/default.conf +++ b/docker/build/default.conf @@ -1,27 +1,26 @@ server { listen 80; - server_name localhost; - root /var/www/demo/public; - location / { - try_files $uri @rewriteapp; - } + server_name localhost; + + root /var/www/demo/public; # Make sure this is where your app files are - location @rewriteapp { - rewrite ^(.*)$ /index.php/$1 last; + index index.php index.html index.htm; + + # Main location block + location / { + try_files $uri $uri/ /index.php?$query_string; } - client_max_body_size 200M; - location ~ ^/index.php(/|$) { - fastcgi_pass php-upstream; - fastcgi_split_path_info ^(.+\.php)(/.*)$; + # PHP-FPM handling + location ~ \.php$ { include fastcgi_params; + fastcgi_pass php-upstream; # This matches the upstream definition fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; - fastcgi_param HTTPS off; - client_max_body_size 200M; - fastcgi_read_timeout 600; + include fastcgi_params; } - error_log /var/log/nginx/symfony_error.log; - access_log /var/log/nginx/symfony_access.log; + # Logs (optional) + error_log /var/log/nginx/error.log; + access_log /var/log/nginx/access.log; }