Skip to content

Commit 1a0e5bc

Browse files
committed
Ajustes del Dockerfile y Conf Nginx
1 parent d1ece89 commit 1a0e5bc

File tree

2 files changed

+85
-50
lines changed

2 files changed

+85
-50
lines changed

Dockerfile

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
1+
# Imagen base con Nginx y PHP-FPM
12
FROM richarvey/nginx-php-fpm:3.1.6
23

4+
# Establecer directorio de trabajo
5+
WORKDIR /var/www/html
6+
37
# Copiar el contenido del proyecto al contenedor
48
COPY . .
59

@@ -18,10 +22,29 @@ ENV LOG_CHANNEL stderr
1822
# Permitir que Composer se ejecute como superusuario
1923
ENV COMPOSER_ALLOW_SUPERUSER 1
2024

21-
# Instalar el módulo zip y otras extensiones necesarias para Laravel
22-
RUN apk update && apk add --no-cache libzip-dev \
23-
&& docker-php-ext-install zip \
24-
&& docker-php-ext-enable zip
25+
# Instalar dependencias necesarias para Laravel y PHP
26+
RUN apk update && apk add --no-cache \
27+
libzip-dev libpng-dev libjpeg-turbo-dev libwebp-dev zlib-dev libxpm-dev \
28+
&& docker-php-ext-install zip gd pdo pdo_mysql bcmath \
29+
&& docker-php-ext-enable zip gd
30+
31+
# Instalar Composer globalmente
32+
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
33+
34+
# Configurar permisos para Laravel
35+
RUN chown -R www-data:www-data /var/www/html \
36+
&& chmod -R 775 /var/www/html/storage /var/www/html/bootstrap/cache
37+
38+
# Instalar dependencias de Composer
39+
RUN composer install --optimize-autoloader --no-dev
40+
41+
# Limpiar caché de APK para reducir el tamaño de la imagen
42+
RUN rm -rf /var/cache/apk/*
43+
44+
# Compilar configuración de Laravel
45+
RUN php artisan config:cache \
46+
&& php artisan route:cache \
47+
&& php artisan view:cache
2548

26-
# Ejecutar el script de inicio
49+
# Ejecutar el script de inicio (inicia Nginx y PHP-FPM)
2750
CMD ["/start.sh"]

conf/nginx/nginx-site.conf

Lines changed: 57 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,61 +1,73 @@
11
server {
2-
# Render provisions and terminates SSL
3-
listen 80;
2+
# Render provisions and terminates SSL
3+
listen 80;
44

5-
# Make site accessible from http://localhost/
6-
server_name _;
5+
# Configuración del nombre del servidor
6+
# Puedes reemplazar "_" con tu dominio si está disponible
7+
server_name _;
78

8-
root /var/www/html/public;
9-
index index.html index.htm index.php;
9+
# Directorio raíz donde se encuentra Laravel
10+
root /var/www/html/public;
11+
index index.php index.html index.htm;
1012

11-
# Disable sendfile as per https://docs.vagrantup.com/v2/synced-folders/virtualbox.html
12-
sendfile off;
13+
# Deshabilitar "sendfile" debido a problemas con sistemas de archivos compartidos
14+
sendfile off;
1315

14-
# Add stdout logging
15-
error_log /dev/stdout info;
16-
access_log /dev/stdout;
16+
# Logs en la salida estándar para entornos Docker/Render
17+
error_log /dev/stdout info;
18+
access_log /dev/stdout;
1719

18-
# block access to sensitive information about git
19-
location /.git {
20-
deny all;
21-
return 403;
22-
}
20+
# Bloquear acceso a información sensible del repositorio .git
21+
location /.git {
22+
deny all;
23+
return 403;
24+
}
2325

24-
add_header X-Frame-Options "SAMEORIGIN";
25-
add_header X-XSS-Protection "1; mode=block";
26-
add_header X-Content-Type-Options "nosniff";
26+
# Encabezados de seguridad
27+
add_header X-Frame-Options "SAMEORIGIN";
28+
add_header X-XSS-Protection "1; mode=block";
29+
add_header X-Content-Type-Options "nosniff";
2730

28-
charset utf-8;
31+
# Configuración de codificación de caracteres
32+
charset utf-8;
2933

30-
location / {
31-
try_files $uri $uri/ /index.php?$query_string;
32-
}
34+
# Manejo de rutas principales
35+
location / {
36+
# Intentar servir el archivo solicitado, luego redirigir a index.php
37+
try_files $uri $uri/ /index.php?$query_string;
38+
}
3339

34-
location = /favicon.ico { access_log off; log_not_found off; }
35-
location = /robots.txt { access_log off; log_not_found off; }
40+
# Configuración para favicon y robots.txt (silencia logs)
41+
location = /favicon.ico { access_log off; log_not_found off; }
42+
location = /robots.txt { access_log off; log_not_found off; }
3643

37-
error_page 404 /index.php;
44+
# Página de error personalizada para 404 (redirige a index.php)
45+
error_page 404 /index.php;
3846

39-
location ~* \.(jpg|jpeg|gif|png|css|js|ico|webp|tiff|ttf|svg)$ {
40-
expires 5d;
41-
}
47+
# Configuración de caché para archivos estáticos (imágenes, CSS, JS, etc.)
48+
location ~* \.(jpg|jpeg|gif|png|css|js|ico|webp|tiff|ttf|svg|woff|woff2|eot|otf)$ {
49+
expires 5d; # Establece la expiración en 5 días
50+
access_log off; # Silencia los logs de acceso para estos archivos
51+
}
4252

43-
location ~ \.php$ {
44-
fastcgi_split_path_info ^(.+\.php)(/.+)$;
45-
fastcgi_pass unix:/var/run/php-fpm.sock;
46-
fastcgi_index index.php;
47-
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
48-
fastcgi_param SCRIPT_NAME $fastcgi_script_name;
49-
include fastcgi_params;
50-
}
53+
# Manejo de archivos PHP
54+
location ~ \.php$ {
55+
include fastcgi_params; # Incluir parámetros estándar de FastCGI
56+
fastcgi_split_path_info ^(.+\.php)(/.+)$; # Separar el script y la información del path
57+
fastcgi_pass unix:/var/run/php-fpm.sock; # Conectar a PHP-FPM usando un socket Unix
58+
fastcgi_index index.php; # Archivo predeterminado para solicitudes PHP
59+
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; # Ruta completa al script PHP
60+
fastcgi_param SCRIPT_NAME $fastcgi_script_name;
61+
}
5162

52-
# deny access to . files
53-
location ~ /\. {
54-
log_not_found off;
55-
deny all;
56-
}
63+
# Bloquear acceso a archivos sensibles y directorios ocultos
64+
location ~ /\. {
65+
log_not_found off; # Silenciar logs si el archivo no existe
66+
deny all; # Denegar acceso
67+
}
5768

58-
location ~ /\.(?!well-known).* {
59-
deny all;
60-
}
69+
# Proteger otros archivos ocultos excepto .well-known (necesario para SSL)
70+
location ~ /\.(?!well-known).* {
71+
deny all;
72+
}
6173
}

0 commit comments

Comments
 (0)