Skip to content

Commit

Permalink
chore: Update Dockerfile-nginx and Dockerfile-php for improved config…
Browse files Browse the repository at this point in the history
…uration
  • Loading branch information
Muneer-Shafi committed Jan 4, 2025
1 parent 0c2dfea commit 4fdcb45
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 20 deletions.
5 changes: 2 additions & 3 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
version: "3.7"

services:
fpm:
container_name: demo_php
Expand All @@ -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
Expand All @@ -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:
Expand Down
13 changes: 12 additions & 1 deletion docker/Dockerfile-nginx
Original file line number Diff line number Diff line change
@@ -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
31 changes: 15 additions & 16 deletions docker/build/default.conf
Original file line number Diff line number Diff line change
@@ -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;
}

0 comments on commit 4fdcb45

Please sign in to comment.