Skip to content

Commit

Permalink
02:06 - Atualizando o Nginx para servir a aplicação
Browse files Browse the repository at this point in the history
  • Loading branch information
CleysonPH committed Sep 28, 2023
1 parent b1b7970 commit 839a7f5
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 10 deletions.
27 changes: 27 additions & 0 deletions app/Dockerfile.prod
Original file line number Diff line number Diff line change
@@ -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" ]
19 changes: 18 additions & 1 deletion docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,10 @@ services:
- 80:80
networks:
- app-network
profiles:
- prod

app:
app-dev:
build:
context: ./app
ports:
Expand All @@ -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:
Expand Down
4 changes: 3 additions & 1 deletion server/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
COPY nginx.conf /etc/nginx/conf.d

RUN mkdir -p /var/www/html && touch /var/www/html/index.php
34 changes: 26 additions & 8 deletions server/nginx.conf
Original file line number Diff line number Diff line change
@@ -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;
}
}

0 comments on commit 839a7f5

Please sign in to comment.