From d0db43610b0a61cbd9df9c3fcd0393956cd84aba Mon Sep 17 00:00:00 2001 From: Tim Lappe Date: Sun, 13 Apr 2025 16:28:34 +0200 Subject: [PATCH] use nginx instead of symfony serve --- Dockerfile | 18 +++++++++++++----- docker-compose.server.yml | 2 +- docker-compose.yml | 4 ++-- docker/nginx/default.conf | 25 +++++++++++++++++++++++++ 4 files changed, 41 insertions(+), 8 deletions(-) create mode 100644 docker/nginx/default.conf diff --git a/Dockerfile b/Dockerfile index 218a767..567b374 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM php:8.2-cli as base +FROM php:8.2-fpm as base # Install system dependencies RUN apt-get update && apt-get install -y \ @@ -21,15 +21,23 @@ RUN curl -sS https://get.symfony.com/cli/installer | bash && \ # Set working directory WORKDIR /var/www/html -CMD ["symfony", "serve", "--port=8000", "--no-tls", "--allow-http", "--allow-all-ip"] +FROM base as dev + +CMD ["php-fpm"] FROM base as production +# Install Nginx +RUN apt-get update && apt-get install -y nginx + # Copy application files COPY . . # Install dependencies -RUN composer install --no-interaction --optimize-autoloader +RUN composer install --no-interaction --optimize-autoloader --no-dev -# Command to run Symfony server -CMD ["symfony", "serve", "--port=8000", "--no-tls", "--allow-http", "--allow-all-ip"] +# Copy Nginx configuration +COPY docker/nginx/default.conf /etc/nginx/conf.d/default.conf + +# Start Nginx and PHP-FPM +CMD ["/bin/bash", "-c", "service nginx start && php-fpm"] diff --git a/docker-compose.server.yml b/docker-compose.server.yml index a0df609..84dcfb5 100644 --- a/docker-compose.server.yml +++ b/docker-compose.server.yml @@ -8,7 +8,7 @@ services: target: production environment: - APP_ENV=prod - - APP_DEBUG=1 + - APP_DEBUG=0 networks: - proxy diff --git a/docker-compose.yml b/docker-compose.yml index b214a46..d8225c6 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -3,9 +3,9 @@ services: build: context: . dockerfile: Dockerfile - target: base + target: production ports: - - 8000:8000 + - 8000:80 environment: - APP_ENV=dev - APP_DEBUG=1 diff --git a/docker/nginx/default.conf b/docker/nginx/default.conf new file mode 100644 index 0000000..cea035d --- /dev/null +++ b/docker/nginx/default.conf @@ -0,0 +1,25 @@ +server { + listen 80; + server_name localhost; + root /var/www/html/public; + + location / { + try_files $uri /index.php$is_args$args; + } + + location ~ ^/index\.php(/|$) { + fastcgi_pass 127.0.0.1:9000; + fastcgi_split_path_info ^(.+\.php)(/.*)$; + include fastcgi_params; + fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name; + fastcgi_param DOCUMENT_ROOT $realpath_root; + internal; + } + + location ~ \.php$ { + return 404; + } + + error_log /var/log/nginx/project_error.log; + access_log /var/log/nginx/project_access.log; +} \ No newline at end of file