use nginx instead of symfony serve

This commit is contained in:
Tim Lappe 2025-04-13 16:28:34 +02:00
parent 9cfbdeaa3c
commit d0db43610b
4 changed files with 41 additions and 8 deletions

View File

@ -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"]

View File

@ -8,7 +8,7 @@ services:
target: production
environment:
- APP_ENV=prod
- APP_DEBUG=1
- APP_DEBUG=0
networks:
- proxy

View File

@ -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

25
docker/nginx/default.conf Normal file
View File

@ -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;
}