From 839a7f580f4a316220e8364977da13584f024850 Mon Sep 17 00:00:00 2001 From: Cleyson Date: Thu, 28 Sep 2023 07:57:12 -0300 Subject: [PATCH] =?UTF-8?q?02:06=20-=20Atualizando=20o=20Nginx=20para=20se?= =?UTF-8?q?rvir=20a=20aplica=C3=A7=C3=A3o?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Dockerfile.prod | 27 +++++++++++++++++++++++++++ docker-compose.yaml | 19 ++++++++++++++++++- server/Dockerfile | 4 +++- server/nginx.conf | 34 ++++++++++++++++++++++++++-------- 4 files changed, 74 insertions(+), 10 deletions(-) create mode 100644 app/Dockerfile.prod diff --git a/app/Dockerfile.prod b/app/Dockerfile.prod new file mode 100644 index 0000000..0a6dbb2 --- /dev/null +++ b/app/Dockerfile.prod @@ -0,0 +1,27 @@ +FROM bitnami/laravel:10 AS builder + +WORKDIR /app + +COPY . . + +RUN composer install --optimize-autoloader --no-dev + +RUN npm install && npm run build + +FROM php:8.2.10-fpm-alpine AS runner + +WORKDIR /var/www + +RUN rm -rf /var/www/html + +RUN docker-php-ext-install pdo_mysql + +COPY --from=builder /app . + +RUN ln -s public html + +RUN chown -R www-data:www-data /var/www + +EXPOSE 9000 + +CMD [ "php-fpm" ] \ No newline at end of file diff --git a/docker-compose.yaml b/docker-compose.yaml index 140c00a..65999d7 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -20,8 +20,10 @@ services: - 80:80 networks: - app-network + profiles: + - prod - app: + app-dev: build: context: ./app ports: @@ -34,6 +36,21 @@ services: - db networks: - app-network + profiles: + - dev + + app-prod: + build: + context: ./app + dockerfile: Dockerfile.prod + env_file: + - ./app/.env + depends_on: + - db + networks: + - app-network + profiles: + - prod networks: app-network: diff --git a/server/Dockerfile b/server/Dockerfile index 06247c1..20078e0 100644 --- a/server/Dockerfile +++ b/server/Dockerfile @@ -2,4 +2,6 @@ FROM nginx:1.21.3-alpine RUN rm /etc/nginx/conf.d/default.conf -COPY nginx.conf /etc/nginx/conf.d \ No newline at end of file +COPY nginx.conf /etc/nginx/conf.d + +RUN mkdir -p /var/www/html && touch /var/www/html/index.php \ No newline at end of file diff --git a/server/nginx.conf b/server/nginx.conf index 378063a..3ebe040 100644 --- a/server/nginx.conf +++ b/server/nginx.conf @@ -1,14 +1,32 @@ server { listen 80; - server_name localhost; - + listen [::]:80; + server_name example.com; + root /var/www/html; + + add_header X-Frame-Options "SAMEORIGIN"; + add_header X-Content-Type-Options "nosniff"; + + index index.php; + + charset utf-8; + location / { - root /usr/share/nginx/html; - index index.html index.htm; + try_files $uri $uri/ /index.php?$query_string; } - - error_page 500 502 503 503 /50x.html; - location = /50x.html { - root /usr/share/nginx/html; + + location = /favicon.ico { access_log off; log_not_found off; } + location = /robots.txt { access_log off; log_not_found off; } + + error_page 404 /index.php; + + location ~ \.php$ { + fastcgi_pass app-prod:9000; + fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name; + include fastcgi_params; + } + + location ~ /\.(?!well-known).* { + deny all; } } \ No newline at end of file